2

I want to add a custom price filed just like the price field which can be seen when we add new products.

I can add a field like this

$fieldset->addField('price', 'text', array(
          'label'     => Mage::helper('menu')->__('Price'),
          'class'     => 'required-entry',
          'required'  => true,
          'name'      => 'price',
      ));

But I don't know how to validate it to take only numeric values. Can anyone help me please?

Or is their any other field type in magento that takes only numeric value?

7

Add class name validate-number

$fieldset->addField('price', 'text', array(
          'label'     => Mage::helper('menu')->__('Price'),
          'class'     => 'required-entry validate-number',
          'required'  => true,
          'name'      => 'price',
      ));
3
  • 1
    validate-not-negative-number for value >= 0 and validate-greater-than-zero for value > 0 – Nalin Savaliya Apr 10 '17 at 7:34
  • very good answer, it helped me right on time... But for me I find that if the value I enter starts with alphabets(e.g. abc100), it detects and give error, but if I enter value like 100abc, it fails and lets system to save. – M Shoaib Qureshi Feb 22 at 8:11
  • I am talking about the validate-not-negative-number and validate-greater-than-zero above. – M Shoaib Qureshi Feb 22 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.