This article introduces an example of using PHP regular expressions to verify whether an email address is valid. Friends in need may wish to refer to it.
The simple code shared below uses PHP regular expressions to verify the validity of the email address. Friends who are interested can study it. Code: <html> <head> <title>php正则验证email地址-bbs.it-home.org</title> </head> <body> <?php /** * 检测输入的email地址是否有效 * by bbs.it-home.org */ if (isset($_POST['posted'])) { $email = $_POST['email']; $theresults = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email, $trashed); if ($theresults) { $isamatch = "有效的email地址"; } else { $isamatch = "无效的email地址"; } echo "经验证,您输入的Email:是" . $isamatch; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="posted" value="true"> 请输入要验证的E-Mail地址: <input type="text" name="email" value="name@example.com"> <input type="submit" value="Validate"> </form> </body> </html> Copy after login |