magento validate mobile number

Magento add mobile number validation in checkout page

magento validate mobile number

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-digitsdefault 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.

The following two tabs change content below.
Ankur Dholakia

Ankur Dholakia

Magento Developer | Entrepreneur at iBiz Technologies
Magento Developer, Entrepreneur, Day Dreamer!
WhatsAppShare
Share on

There are no comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Start typing and press Enter to search

Shopping Cart