I used Magento phone number validation validate-length maximum-length-11 minimum-length-11 validate-digits for phone number but i want to first digit starting with(7,8,9) and after that 9 digit will come how i restrict ?

  • how many digit altogether? Sep 30, 2015 at 12:35
  • I got a solution check my answer
    – Magento 2
    Sep 30, 2015 at 12:40

3 Answers 3


Create this file custom-validate.js and place in js folder.

Validation.add('validate-phoneLax', 'Please enter a number starting from 7 or 8 or 9 and should be exactly 11 digits. For example 71234567890', function(v) {
    return Validation.get('IsEmpty').test(v) || /^7[0-9]{10}$/g.test(v) || /^8[0-9]{10}$/g.test(v) || /^9[0-9]{10}$/g.test(v)

Now just need to call this file from xml so that it is added in that particular page. If you want it to be in every page then just add in local.xml

    <reference name="head">
        <action method="addJs"><script>custom-validate.js</script></action>

Now when you have validate-phoneLax class name in input filed it should validate as you expect.


We are overriding phoneLax validation class.

I haven't tested but should work.

More Reading


i got answer to my question

<input type="text" name="billing[telephone]" value="<?php echo $this->escapeHtml($this->getAddress()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?> validate-mobileno" id="billing:telephone" placeholder="Mobile"/>

<script type="text/javascript">
if(Validation) {
['validate-mobileno','Enter correct mobile number (Eg:919986858483)',
var timePat ="^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$";
// var matchArray = v.match(timePat);
if(v.length > 0){
if(v.length !=12){
    return false;
   }else if(v[0] != 9 || v[1] != 1 ){

    return false;
   }else if(v[2]!=9 && v[2]!=8 && v[2]!=7){

    return false;

return true;

}else {
return false;

 var dataForm = new VarienForm('form-validate', true);

Add your own validation class

Validation.add('Your Class Name','Your Validation Message',function(v){
    return "check Your patterns here";

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.