Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*******************************************************
* 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