Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel validation for this number +852 1111 2222?

Suppose we have number +852 1111 2222 in format .What is the Laravel validation for this number(regular expression) with + symbol and allow space between number?

'phone_number'  => 'required|regex:/(^[0-9 ]+$)+/',

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Regular expression will be good example for you as you the format of phone number won’t change you cant take this regex patter as example

'phone_number'  => 'required|regex:/^\+\d{3}\s\d{4}\s\d{4}$/',

In case the phone number prefix doesn’t change you can include it directly in the pattern like this

'phone_number'  => 'required|regex:/^\+852\s\d{4}\s\d{4}$/',

Here is the link to regex101

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading