1
I want to add a new field in system.xml which allows only numeric values.

How can I validate that?

Here is my code

<config>
    <sections>
        <newsletter translate="label" module="newsletter">
            <label>Newsletter</label>
            <tab>phone</tab>
            <frontend_type>text</frontend_type>
            <sort_order>110</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
       </newsletter>
  </sections>
</config>
6

Usually in your file System.xml, if you needed to add a restriction to a field you have to add embedded validators into your file. There are numerous validators like

  • validate-select
  • required-entry
  • validate-number
  • validate-digits

and many more

In this case, you need to add validate-number like

<config>
        <sections>
            <newsletter translate="label" module="newsletter">
                <label>Newsletter</label>
                <tab>phone</tab>
                <frontend_type>text</frontend_type>
                <sort_order>110</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <validate>validate-number</validate>
         </newsletter>
      </sections>
    </config>

That's it.

| improve this answer | |

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.