Skip to content

Instantly share code, notes, and snippets.

Created December 4, 2015 17:28
Show Gist options
  • Save anonymous/21867b9fb2e6b1f7ae3f to your computer and use it in GitHub Desktop.
Save anonymous/21867b9fb2e6b1f7ae3f to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/harshitanand 's solution for Bonfire: Validate US Telephone Numbers
// Bonfire: Validate US Telephone Numbers
// Author: @harshitanand
// 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