Hi i want to validate the mobile number in custom module my code is

<input type="text" class="input-text required-entry validate-length maximum-length-10 minimum-length-10 validate-digits" id='adcontact' name='adcontact' data-validate="{required:true, 'validate-number':true}"/>

but it is not working. when i enter only 2 or 3 digits form get submitted


If want to ten digital then you need do some code at rules.js

Copy rules.js from vendor/magento/module-ui/view/base/web/js/lib/validation/rules.js

to put it to


Then add new js rules mobiletendigit for 10 digit mobile after mobileUK

  "mobiletendigit": [
        function(value) {
            return value.length > 9 &&  value.length < 11 
            && value.match(/^\d{10}$/);
        $.mage.__('Please specify a valid 10 digits mobile number')

Remove pub/static folder contents and run deploy command,

php bin/magento setup:static-content:deploy

Then you need add this new class mobiletendigit to your field.

<input type="text" class="input-text required-entry mobiletendigit validate-digits" id='adcontact' name='adcontact' data-validate="{required:true, 'validate-number':true}"/>
  • 1
    Question from @alexandre-iglesias-rodrigues : sorry for easy question, but in which file the field is in ? – diazwatson Aug 9 '17 at 20:56
  • Hi Amit Bera, i fallowed above step but it did not work for me. – Sarvesh Tiwari Feb 16 '18 at 9:20
  • Have u done clear cache & do static content deploy – Amit Bera Feb 16 '18 at 9:22
  • Not working for me as well, even I have deploy the content – Purushotam Sharma Dec 3 '19 at 10:29

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.