Для получения полного доступа
зарегистрируйтесь

Валидация email согласно RFC822 - аналог стандартной php валидации: filter_var($email, FILTER_VALIDATE_EMAIL).


Валидация email согласно RFC822 - аналог стандартной php валидации: filter_var($email, FILTER_VALIDATE_EMAIL).

<?php
function validateEmail($email, $bStrict=false) {
    $pattern = '/^("[\w-\.\s]+")|(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/i';
    return (boolean)preg_match($pattern, $email);
}
function validateEmail2($email) {
    $email = trim($email);
    if (strlen($email)<=0) {return false;}
    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {return true;}
    return false;
}
$emails = array('niceandsimple@example.com','very.common@example.com','a.little.lengthy.but.fine@dept.example.com','disposable.style.email.with+symbol@example.com','other.email-with-_dash@example.com','user@[IPv6:2001:db8:1ff::a0b:dbd0]','"much.more unusual"@example.com','"very.unusual.@.unusual.com"@example.com','"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
    'postbox@com','admin@mailserver1','!#$%&\'*+-/=?^_`{}|~@example.org','"()<>[]:,;@\\\"!#$%&\'*+-/=?^_`{}| ~.a"@example.org','" "@example.org','üñîçøðé@example.com','üñîçøðé@üñîçøðé.com',
);
foreach($emails as $email) {$tmp['custome_pattern:'][] = validateEmail($email);}
foreach($emails as $email) {$tmp['filter_var (php standard function):'][] = validateEmail2($email);}
var_dump($tmp);

Чтобы увидеть комментарии, нужно быть участником сообщества

Регистрация