Created
December 10, 2019 13:29
-
-
Save CEOehis/4f005d6b6089a7599a2767446500570f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function telephoneCheck(str) { | |
| // Good luck! | |
| const numberRegex = /^((\(\d{3}\)[ -]?)|(\d{3}[ -]?))\d{3}[ -]?\d{4}$/; | |
| // check if it starts with 1 | |
| if(str.startsWith('1')) { | |
| return numberRegex.test( | |
| str.substring(1).trim() | |
| ); | |
| } | |
| return numberRegex.test(str); | |
| } | |
| telephoneCheck("555-555-5555"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment