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

Johny22's avatar

Phone request validation

Hello, can you advise me how I would best validate such a phone number format as best I can? +421915490545 area code +421 and then 10 numbers. I'm using a request validator and I've tried it with regey, but I can't

0 likes
5 replies
JoaoPedroAlves's avatar

The number you provided +421915490545 is formed by +421 then 9 numbers 915490545 instead of 10.

But a regex to validate the rule (+421 then 10 numbers) could be something like:

'phone' => 'required|regex:/\+421\d{10}/'

in your validation array

martinbean's avatar

@johny-22 The best way is to send the phone number to a service like Twilio for validation, who will then return the phone number in both the E.164 format, as well as the “local” formatted version.

Don’t try and write a regular expression yourself because there are a multitude of ways a user can input a phone number and I can guarantee your regular expression won’t match all of them.

Please or to participate in this conversation.