Benjamin B.
Benjamin B.

Reputation: 483

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

Upvotes: 2

Views: 69

Answers (1)

anubhava
anubhava

Reputation: 785038

This regex should work:

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

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

Upvotes: 2

Related Questions