H
H
HAbRAhabp2016-01-26 19:01:05
PHP
HAbRAhabp, 2016-01-26 19:01:05

A pattern for a mobile phone?

Help compose a regular expression for a mobile phone with +. Everything I searched on Google doesn't work. I try like this:

if (preg_match('^\+\d{7,15}$', $_GET['num'])) echo 'ok';
else echo 'error';

so
if (preg_match("/^\+\d{7,15}$/", $_GET['num'])) echo 'ok';
else echo 'error';

I get in the first case error and warning
Warning: preg_match(): No ending delimiter '^' found
, in the second error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2016-01-26
@HAbRAhabp

In php, you need to wrap the regular expression in paired characters

~^\+\d{7,15}$~
/^\+\d{7,15}$/
`^\+\d{7,15}$`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question