Option 1
You can add minimum value validation by backend_model
, for example.
<field id="base_url" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Base URL</label>
<backend_model>Magento\Config\Model\Config\Backend\Baseurl</backend_model>
<comment>Specify URL or {{base_url}} placeholder.</comment>
</field>
Then you can find the beforeSave
method at \m9agento210\vendor\magento\module-config\Model\Config\Backend\Baseurl.php
public function beforeSave()
{
$value = $this->getValue();
try {
// You can write some validation here.
} catch (\Magento\Framework\Exception\LocalizedException $e) {
throw $error;
}
}
This is an example, you can implement this in your custom module.
Option 2
<field id="custom_email" translate="label comment" sortOrder="0" type="text" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Enter Email Id</label>
<validate>validate-email</validate>
</field>
Some Important validation classes are
'validate-no-html-tags' => 'HTML tags are not allowed'
'validate-select' => 'Please select an option.'
'required-entry' => 'This is a required field.'
'validate-number' => 'Please enter a valid number in this field.'
'validate-digits' => 'Please use numbers only in this field. Please avoid spaces or other characters such as dots or commas.'
'validate-date' => 'Please enter a valid date.'
'validate-email' => 'Please enter a valid email address. For example johndoe@domain.com.'
'validate-url' => 'Please enter a valid URL. Protocol is required (http://, https:// or ftp://)'
'validate-not-negative-number' => 'Please enter a number 0 or greater in this field.'
'validate-zero-or-greater' => 'Please enter a number 0 or greater in this field.'
'validate-state' => 'Please select State/Province.'
'validate-cc-number' => 'Please enter a valid credit card number.'
'validate-data' => 'Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.'
Hope it helps.