Last active
August 26, 2020 21:27
-
-
Save edwinmunguia/4b4c4175e3deddade34b99e501a36ba8 to your computer and use it in GitHub Desktop.
Regex to validate Honduras phone number using Javascript
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 validPhoneNumberRegex = /^(2|3|8|9)\d{3}-?\d{4}$/; | |
const isValidPhoneNumber = (input) => validPhoneNumberRegex.test(input); | |
//Test cases | |
//Valid number | |
if (isValidPhoneNumber("9837-4050")) console.log("Valid"); | |
else console.log("Invalid"); | |
//Invalid numbers | |
if (isValidPhoneNumber("78374050")) console.log("Valid"); | |
else console.log("Invalid"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment