Last active
July 17, 2021 06:24
-
-
Save 4k45hv3rm4/44ce80c159b436b2bc14f739c08bb176 to your computer and use it in GitHub Desktop.
Validate Mobile Number function
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
validateMobile(phone) { | |
const pattern = /^([0]|\+91)?[6789]\d{9}$/; //Regex Valid for all Indian mobile numbers | |
if (!isNaN(phone) && phone.match(pattern) ) return true; | |
return false; | |
} | |
}, |
Nice clap
Some suggestions:
* There are some syntax error which will prevent this from running. * You can slightly shorten the regexp: `/^([0]|\+91)?[6-9]\d{9}$/` * Instead of `phone.match(pattern)`, use `pattern.test(phone)` as it returns a boolean value. * No need of the `if` clause, you can simply do this: `return (!isNaN(phone) && pattern.test(phone))`
Got it ! .
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice 👏
Some suggestions:
/^([0]|\+91)?[6-9]\d{9}$/
phone.match(pattern)
, usepattern.test(phone)
as it returns a boolean value.if
clause, you can simply do this:return (!isNaN(phone) && pattern.test(phone))