Muhammad Usama Saeed
Muhammad Usama Saeed

Reputation: 634

block specific type of email address in php via regex

I use the following regex pattern for validating the email address that works fine.

/^[^\@]+@.*\.[a-z]{2,6}$/i

But the problem is I want to generate error if email like [email protected] are enter. Actually all those emails are invalid which have characters same as before & after **.** like [email protected] invalid, [email protected] invalid

Upvotes: 0

Views: 265

Answers (1)

Barmar
Barmar

Reputation: 780869

You can use a back-reference in a regexp to test if two parts are the same. In PHP you'd write:

if (preg_match('/^(\w+)\.\1@.*/', $email)) {
    echo "That's a spammy name";
}

Upvotes: 1

Related Questions