Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nirajkrz/f234a739186c41536d2b to your computer and use it in GitHub Desktop.
Save nirajkrz/f234a739186c41536d2b 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