平成30/ 2018-10-22 00:46
cakephp のメール形式チェック
//
function hostnameCk($str){ // thanks CakePHP.
    $regex = '/^(?:[a-z0-9][-a-z0-9]*\.)*(?:[a-z0-9][-a-z0-9]{0,62})\.(?:(?:[a-z]{2}\.)?[a-z]{2,4}|museum|travel)$/iu';
    return preg_match($regex, $str);
}
//
function emCk($str){ // thanks CakePHP.
    if(
    !($em = preg_split("/@/u", $str)) or
    count($em) <> 2
    ){
        return false;
    }
    if(
    !hostnameCk($em[1])
    ){
        return false;
    }
    $regex = '/^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*$/ui';
    return preg_match($regstr, $em[0]);
}