Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular expression to detect consecutive numbers - not working for non-English input

Hi All I have this code that checks for 5 or more consecutive numbers :

if (preg_match("/\d{5}/", $input, $matches) > 0)
return true;

It works fine for input that is English, but it's tripping up when the input string contains Arabic/multibyte characters - it returns true sometimes even if there aren't numbers in the input text.

Any ideas ?

like image 930
Sherif Buzz Avatar asked Dec 07 '25 09:12

Sherif Buzz


1 Answers

You appear to be using PHP.

Do this:

if (preg_match("/\d{5}/u", $input, $matches) > 0)
return true;

Note the 'u' modifier at the end of expression. It tells preg_* to use unicode mode for matching.

like image 80
Dennis Kreminsky Avatar answered Dec 09 '25 22:12

Dennis Kreminsky