Skip to content

Instantly share code, notes, and snippets.

@dedicatedfuture
Created July 22, 2015 17:40
Show Gist options
  • Save dedicatedfuture/720fd2a5a94c94b67510 to your computer and use it in GitHub Desktop.
Save dedicatedfuture/720fd2a5a94c94b67510 to your computer and use it in GitHub Desktop.
function telephoneCheck(str) {
// Good luck!
var valid = false;
if(!str.match(/^\([^\(\)]{10}\)$/g)){
if(!str.match(/^\-/g)){
var reg = /[^0-9]/g;
str = str.replace(reg, "");
if(str.length ===10){
valid = true;
}else if(str.length === 11){
if(str[0]===1){
valid = true;
}
}
}
}
return valid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment