Validate phone number using RegEx and JavaScript

A function to validate phone numbers using JavaScript and regular expressions. It will work with all valid US phone numbers in all popular formats.
  1. function ValidatePhone(strPhone)
  2. {
  3.  var regPhone = /^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}({0,1}|\s{0,1})\d{2}({0,1}|\s{0,1})\d{2}$/;
  4.  if (strPhone.match(regPhone))
  5. {
  6. return true;
  7. }
  8. else
  9. {
  10. return false;
  11. }
  12. }

Leave a Reply

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

Back To Top