How can i validate a phone number with plus sign optional only at the beginning and after that any number of digits with number only.
I tried this:-
/^\+(?:[\d]*)$/
How will be the modification
How can i validate a phone number with plus sign optional only at the beginning and after that any number of digits with number only.
I tried this:-
/^\+(?:[\d]*)$/
How will be the modification
/^\+?(?:[\d]*)$/
The questionmark tells that the plus sign can be there or not. However, your expression can be optimized quite a bit:
/^\+?\d+$/
I changed the *
to a +
as the expression would match just a plus sign. \d*
suggests that it should match 0 or more digits.
Here's a demo on Regexr.
Expression for plus, hyphen and numbers in a phone number
^\+?\d+-?[0-9]+-?[0-9]+$