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

Example of php regular verification email address

WBOY
Release: 2016-07-25 08:56:44
Original
1025 people have browsed it
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


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template