I am not very experienced with regex and I need to validate phone numbers using javascript.
I have a textbox which need to be allowed to accept multiple phone numbers with a delimiter of ';' and the characters that can be allowed for the phone numbers are
- Numbers
- ‘+’
- ‘-‘
Could someone help me on how I can acheive this using javascript and regex/ regular expressions?
Example:
+91-9743574891;+1-570-456-2233;+66-12324576
I tried the following:
^[0-9-+;]+$
Am not sure if this is correct.
You have placed
-in wrong place so, yourregexis not working.Try this(your RegEx, but slightly modified):
or
To include a hyphen within a character class then you must do one of the following:
\-,As the hyphen is used for specifying a range of characters. So, regex engine understands
[0-9-+;]+match any of the characters between0to9,9to+(all characters having decimal code-point57[char9] to43[char+] and it fails) and;.