Created
December 11, 2018 18:21
-
-
Save iCaspar/923b20c9cd8121a525d63cea809d1b0c to your computer and use it in GitHub Desktop.
Function to validate a US phone number
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
function telephoneCheck(str) { | |
const usPhoneRegex = /^(?:1\s?)?(?:\d{3}|\(\d{3}\))[\s|-]?\d{3}[\s|-]?\d{4}$/ | |
return usPhoneRegex.test(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment