php 邮箱验证


$reply = '';
    if (isset($_POST['email'])) {
        $email = $_POST['email'];
        $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
        if (preg_match($pattern,$email,$match)) {
            print_r($match);
            $user_name = preg_replace($pattern,"$1",$email);
            $domain_name = preg_replace($pattern,"$2",$email);
            $reply .= "用户名:".$user_name."
"
; $reply .= "域名:".$domain_name.'
'
; } else { $reply = '邮箱格式不正确'; } } ?> html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Documenttitle> head> <body> <h1>正则验证邮箱h1> <form action="" method="post"> 邮箱:<input type="text" name="email"> <input type="submit" value="邮箱验证"> form> echo $reply;?> body> html>

你可能感兴趣的:(php 邮箱验证)