Created
February 12, 2017 01:36
-
-
Save asimmittal/d7881420922ca42a2932dc9567a6a2cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************* | |
* 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