Home >Backend Development >PHP Tutorial >Example of php regular verification email address

Example of php regular verification email address

WBOY
WBOYOriginal
2016-07-25 08:56:441027browse
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>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn