D
D
Denis2015-01-07 11:32:40
PHP
Denis, 2015-01-07 11:32:40

How to check the domain zone in a line with email?

Hello.
Please help me compose a regular expression for filtering the domain zone of outgoing e-mail's users.
First, I define an array with valid domain zones:

$allowedDomainZones = array(".ru", ".com", ".info", ".org", ".net"); // etc.

Then comes the check:
$invalidEmail = "[email protected]"; // e.g. define invalid string with email
$regularExpression = "^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"; 
if (preg_match($regularExpression, $invalidEmail)) {
     echo $email . " email accepted! Ok =)";
} else { 
     echo $email . " you have entered invalid email =(";
}

Question: how to add a check of domain zones from an array to a regular expression $allowedDomainZones?
General task: to prevent registration of users who specify a domain zone outside
$allowedDomainZones = array(".ru", ".com", ".info", ".org", ".net");
domain zones.
We are talking about an information portal that used to work on Dupal 6, as a result of the lack of filtering, the database is frankly polluted by spammer accounts, accounts with a login like: admiN, ADMIN, ♥ My honey ♥ and other rubbish in ASCII.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Melkij, 2015-01-07
@m5web

And it is possible to be curious about the general task? At which time of New gTLDs is a whitelist of first level domains required?

$regularExpression = "^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-.]+(".join('|', $allowedDomainZones).")$";

T
Taras Labiak, 2015-01-07
@kissarat

You can't expect email to have any format. We can only say with the statement that these are two lines in which there is no space, separated by @, in the right of which there must be at least one dot. There are hundreds of top-level domains, and there are also hit addresses. Some characters in the username may be ignored by a particular mail server, so it is possible to register several accounts for the same mailbox.

V
Vapaamies, 2015-01-07
@vapaamies

Never check e-mail addresses against RFC standards .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question