Benjamin B. Benjamin B. - 1 year ago 107
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 Source

This regex should work:


Working Demo:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download