A
A
asferot2018-11-21 11:53:41
Yii
asferot, 2018-11-21 11:53:41

How to write international phone validation with regular expression in Yii2?

How to write regular expression phone validation in Yii2 that will match any phone for all countries?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-11-21
@asferot

Good morning.
In yii2 you can check like this

// +38(073)222 33 44
['car_phone', 'match','pattern' => "#^+\d{1,3}\(\d{1,3}\)\d{3}  \d{2}  \d{2}$#"]

This will check for Ukraine, Russia.
But you do not forget that there are many countries and each has its own format for writing the number. So you will hardly find a universal solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question