Created
May 29, 2024 22:12
-
-
Save moriarty99779/376fcd8fb1a1e56cfd554ac6f9796517 to your computer and use it in GitHub Desktop.
Javascript - Check if a string is a valid US telephone 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
const checkIsValidUSPhoneNumber = (phone) => /^(?:(?:\+1\s?)?(?:\(?\d{3}\)?[\s.-]?)?\d{3}[\s.-]?\d{4})$/.test(phone); | |
document.write(checkIsValidUSPhoneNumber("+1 (123) 456-7890")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment