-1

I want a validation on telephone field when adding shipping address.

Number will start only with 7 Or 8 Or 9.

0

Can you please try this following script


function validatePhone() {
var a = document.getElementById(txtPhone).value;
    var filter = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/;
   if (a.charAt(0) =="9" || a.charAt(0) =="8" || a.charAt(0) =="7" ){
  alert("");
   }
   else{
   if (filter.test(a)) {
        return true;
    }

    else {
        return false;
    }
    }
}
| improve this answer | |
  • I have problem about the file location where i have to put the code... – Taslim Waris Apr 3 '17 at 6:43
  • Did you have "id" or "class" for the telephone input field ?? – Jenith Samuel Apr 3 '17 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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