Last active
July 25, 2016 04:55
-
-
Save jtribble/674ffe21471ee5c7a1db to your computer and use it in GitHub Desktop.
Is string a valid us phone number
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
/** | |
* Is string a valid phone number? | |
* | |
* @param {string} str | |
* @return {boolean} | |
*/ | |
var isValidPhone = function (str) { | |
if (!str) return false; | |
var count = str.replace(/[^0-9]/g, '').length; | |
return count == 10 || count == 11; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment