Magento – Magento 2: system.xml saved config validation

databasemagento2system.xml

I developed an extension for Magento2 that saves configs using a system.xml and I would like to validate the values the user inputs.
How can i validate those values?

Best Answer

You can apply validation on textbox in magento 2 like this,

<field id="custom_path" translate="label comment" type="text" sortOrder="4" showInDefault="1" showInWebsite="0" showInStore="0">
   <label>Custom Admin Path</label>
   <validate>required-entry</validate>              
   <comment>You will have to sign in after you save your custom admin path.</comment>
</field>

You can keep validate-alphanum or validate-number for alphanumeric and numeric value inside validate tag.

Thanks.

Related Topic