Skip to content

Instantly share code, notes, and snippets.

@asimmittal
Created February 12, 2017 01:36
Show Gist options
  • Save asimmittal/d7881420922ca42a2932dc9567a6a2cd to your computer and use it in GitHub Desktop.
Save asimmittal/d7881420922ca42a2932dc9567a6a2cd to your computer and use it in GitHub Desktop.
/*******************************************************
* validatePhone
* return true if the string 'p' is a valid phone
*******************************************************/
function validatePhone(p){
var phoneRe = /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/;
var digits = p.replace(/\D/g, "");
return phoneRe.test(digits);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment