4

I want to Validate Max-limit in system configuration field. i have used some of classes for other validation but did not found any class for max or min text limit for system configuration filed.

https://i.sstatic.net/r246F.png

2

2 Answers 2

6

You can use this code for better output with validation :

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <system> <tab id="tabID" translate="label" sortOrder="10"> <label>Tab Name</label> </tab> <section id="sectionID" translate="label" type="text" sortOrder="300" showInDefault="1" showInWebsite="1" showInStore="1"> <label>General Configuration</label> <tab>Section</tab> <group id="groupID" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <field id="fieldID" translate="label comment" sortOrder="0" type="text" showInDefault="1" showInWebsite="0" showInStore="0"> <label>Maximum Number of Items to Display</label> <validate>required-entry validate-digits validate-not-negative-number validate-length minimum-length-7 maximum-length-20 </validate> </field> </group> </section> </system> 
  • required-entry : For required field
  • validate-digits : For use numbers only in this field.
  • validate-not-negative-number : For enter a number 0 or greater.
  • validate-length : For a specific valid length.
  • minimum-length-7 maximum-length-20 : Min length is 7 and Max length is 20.
5

Thank you for asking about this validation. Use this validation for your query:

<validate>validate-length maximum-length-50</validate> 

For Example:

<group id="customer_service" translate="label" type="text" sortOrder="35" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Customer Service</label> <field id="number" translate="label" type="text" sortOrder="9" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Enter Contact Number</label> <comment>Please enter an internationalized version of the phone number. For example +91 XXX XXXXXXX</comment> <validate>validate-length maximum-length-22</validate> </field> </group> 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.