Regex for phone number validation
How can I construct regex to validate phone number? That is:
Starts with +234
Followed by 10 digits
I have tried this pattern: pattern='^[+234][0-9]{10}$' but not working with the inputted value.
I will appreciate help here
Might be worth checking out this package.
@kingsleyo If you only want to handle +234 followed by 10 digits, ^\+234[0-9]{10}$ will do the trick.
You have to be carefull with the + as it is used as a quantifier in regex. That's why you have to write \+ for it to work.
the problem is in [+234]
it meens that first digit can match anything in first brackets: + or 2 or 3 or 4, then followed by exact 10 digits
if you want to hardcode country you should do
^+234[0-9]{10}$
if you need to validate any country code followed by exact 10 digits you should try this
^+[0-9]{1,3}[0-9]{10}$
otherwise you can use standart regex for phone:
^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$
Please or to participate in this conversation.