Benjamin B. Benjamin B. - 22 days ago 5
PHP Question

Regex repeated characters

I have one regex to check if the 6 last numbers of a variable are not the same.
I don't understand why my regex is not working ?

If $tel = "0601244567" it's ok but if $tel = "0601555555" or anything with the last 6 characters it's not working.

if (!preg_match("/^0[1-79][0-9]{2}(?!(\d)\1{5}$)\d{6}$/i", $tel)) {
$errors[] = array(
"tel" => "Wrong phone number."
);
}


Thanks in advance

Answer

This regex should work:

^(?!.*?(\d)\1{5}$)0[1-79]\d{8}$

Working Demo: http://regex101.com/r/xN8nY6