magento validate mobile number
Magento add mobile number validation in checkout page
To Validate mobile number in checkout page, open your template file for checkout page (billing/shipping.phtml if checkout is default). find input field of mobile number and add following classes to it:
1) validate-digits – default class. only digits are allowed.
2) validate-length maximum-length-10 minimum-length-10 – default classes. checks length of input,allows if length is exactly 10.
3) validate-mobilenumber – custom class. it will check weather input value starts from 6,7,8,9 or not as mobile number starts from these digits only. Read below how to create it.
Find this code in template file :
var billingForm = new VarienForm(‘co-billing-form’);
and insert this code after that. We are adding custom validation rule here.
Validation.add(‘validate-mobilenumber’,’Invalid Mobile Number’,function(v) {
var n = v.charAt(0);
if(n == 6 || n == 7 || n == 8 || n == 9) {
return true;
}
else {
return false;
}
});
So you need to add these 5 classes to mobile number input field, to confirm that user has entered mobile number only.
By this way you can add any custom validation rule as per your requirements.
Let me know in comments if any issues.

Ankur Dholakia

Latest posts by Ankur Dholakia (see all)
- Create module in magento 2 - January 12, 2016
- Magento 2 – Theme Development and Theme Structure - January 6, 2016
- Magento themes | Magento templates | Responsive Magento themes - December 12, 2015
There are no comments