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

  • Hi Nitin, what you did so that it works! I faced the same issue! Oct 28, 2020 at 10:47

1 Answer 1


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, 2017 at 20:56
  • Hi Amit Bera, i fallowed above step but it did not work for me. Feb 16, 2018 at 9:20
  • Have u done clear cache & do static content deploy
    – Amit Bera
    Feb 16, 2018 at 9:22
  • Not working for me as well, even I have deploy the content Dec 3, 2019 at 10:29
  • Hi Amit, Can you please tell me should we inject the rule.js file in di.xml? Oct 28, 2020 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.