Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KingsleyO's avatar

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

0 likes
4 replies
dylanduault's avatar

@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.

Aktheon's avatar

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]*$
1 like

Please or to participate in this conversation.