Answer the question
In order to leave comments, you need to log in
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.
$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 =(";
}
$allowedDomainZones
? $allowedDomainZones = array(".ru", ".com", ".info", ".org", ".net");
domain zones. Answer the question
In order to leave comments, you need to log in
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).")$";
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question