Here is a custom script that I have written to validate a phone number. Hope this might help you 🙂
function ValidatePhone() { var phoneRegExp = /^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/; var phoneVal = $("#txtPhone").val(); var numbers = phoneVal.split("").length; if (10 <= numbers && numbers <= 20 && phoneRegExp.test(phoneVal)) { alert("SUCCESS"); } }
The above function validates all kinds of generic international phone numbers, including that of the USA, may include () around area code as well as period, dash, space or nothing seperating numbers. International code needs to be seperated from rest by period, space or dash and my be prefixed with plus. Not overly restrictive but limits size and repetition of codes.
Phone number length should be minimum of 10 digits and maximum of 20 digits
Matches: 2155552527|(215) 555 2527|215.555.2527|+1 215-555-2527|+1.215.555.2527
Non-matches: +1215.555.2527|321654|+11+27 215-555-2527
Thanks for this regexp 😉 I’ll use it next time !
Thank you for the regexp too. 🙂
Pingback: Phone number validation in jQuery | .dan's blog
Thank you for the regexp, its work 😀
Thanks dude
it works for us… thank you
what if user enter all 20 digits
Hi,
I want to use only this format (123) 456 – 7890. Please let me know “/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/” what i have to change for this format.
Looking forward your reply.
Here you go – “/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[ ][-. –][ ]?([0-9]{4})$/”. Happy Coding!