<?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."<br/>"; $reply .= "域名:".$domain_name.'<br/>'; } else { $reply = '邮箱格式不正确'; } } ?> <!doctype 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>Document</title> </head> <body> <h1>正则验证邮箱</h1> <form action="" method="post"> 邮箱:<input type="text" name="email"> <input type="submit" value="邮箱验证"> </form> <?php echo $reply;?> </body> </html>
php 邮箱验证
最新推荐文章于 2023-12-18 11:01:06 发布