Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2015 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/0b7e2d77a44ca48ecaed to your computer and use it in GitHub Desktop.
Save anonymous/0b7e2d77a44ca48ecaed to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/nirajkrz 's solution for Bonfire: Validate US Telephone Numbers
// Bonfire: Validate US Telephone Numbers
// Author: @nirajkrz
// Challenge: http://www.freecodecamp.com/challenges/bonfire-validate-us-telephone-numbers
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function telephoneCheck(str) {
// Good luck!
var re = /^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$/;
return re.test(str);
}
telephoneCheck("555-555-5555");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment