How to Add Validation in System Configuration in Magento 2

How to Add Validation in System Configuration in Magento 2

Magento 2 is a flexible platform that allows extending its functionality to satisfy the business requirements. Data validation is one such integral part that needs to be implemented for any type of E-commerce stores.

Not only frontend, but you may also want to add validation in system configuration in Magento 2. For example, validate the Email, check for the blank field, etc.

Using the below solution, you can validate any type of input fields in the Magento 2 stores configuration such as text field, date, drop-down, etc. as shown in the figure:

How to Add Validation in System Configuration in Magento 2

Method to Add Validation in System Configuration in Magento 2:

Place the below code at app/code/Meetanshi/HelloWorld/etc/adminhtml/system.xml

That’s it.

Any doubts? Use the Comments section below to mention them. I’ll be happy to help.

Feel free to share the solution with fellow developers via social media to validate the input fields in Magento 2 system configuration.

Thanks.

5
(based on 4 Reviews)

Sanjay is a co-founder at Meetanshi. He is a certified Magento developer who loves creating Magento E-commerce solutions. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply