Created
December 4, 2015 17:28
-
-
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
This file contains 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
// 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