Last active
December 16, 2019 11:22
-
-
Save parwatcodes/75079e7fba443a89961494f3575a3610 to your computer and use it in GitHub Desktop.
phone number validation
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 validate(phone) { | |
var regex = /^\+(?:[0-9]?){6,14}[0-9]$/; | |
if (regex.test(phone)) { | |
// Valid international phone number | |
return 'valid' | |
} else { | |
return 'invalid' | |
// Invalid international phone number | |
} | |
} | |
phone = '+9779805779427' | |
console.log(validate(phone)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment