Validate 10 Digits Mobile Number in Magento 2

In this blog, we will discuss how to validate 10 digits mobile number in Magento 2. Please read the blog.


C:\wamp\www\project folder\lib\web\mage\validation.js 
Add ?
After (“mobileUk”) any place where you want: ?

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

And add in your html file ?


Under >> Class=”validate-digits mobileIN required-entry”

Validate-digits ? For digit validation.

mobileIN ? For 10 digits no validation.

Required-entry ? Field should not be null.

After that


   ? Php bin/magento setup:upgrade     //(MUST)
   ? Php bin/magento setup:static-content:deploy      //(MUST)
   ? Php bin/magento cache:clean  
   ? Php bin/magento cache:flush

You can use the code in Magento development. Please share your review in the comment section.

Comments

We Serve clients globally in diverse industries

Stay Upto Date With Our Newsletter.