M
M
mapleart2018-02-05 16:39:55
PHP
mapleart, 2018-02-05 16:39:55

how to check phone number in php

Hello!
I'm using the Inputmask
library There are phone input masks https://github.com/RobinHerbots/Inputmask/blob/4.x...
in the format:

+376-###-###
+971-5#-###-####
+971-#-###-####
+93-##-###-####

What is the easiest way in php for me to check if these masks match?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tolmachev, 2018-02-05
@dark_tke

Write regular expressions and use preg_match to check
+376-###-###

/^(\+376)-(\d{3})-(\d{3})$/g

+971-5#-###-####
I recommend building all expressions through https://regex101.com/ There is validation, hints and much more useful stuff.
If you need expressions for other numbers, try to do it yourself, if you can’t handle it, write here in the comments, I’ll write

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question