Forked from anonymous/bonfire-validate-us-telephone-numbers.js
Created
December 8, 2015 21:10
-
-
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
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: @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