php邮箱地址正则表达式验证_php技巧

WBOY
Release: 2016-05-16 20:04:51
Original
1994 people have browsed it

我们最经常遇到的验证,就是电子邮件地址验证。网站上常见。各种网页脚本也都常用“正则表达式”(regular expression)对我们输入的电子邮件地址进行验证,判断是否合法。有的还能分解出用户名和域名。现在用PHP语言实现一下电子邮件地址验证程序,用的是PHP正则表达式库。
源代码如下:

<?php header ( "Content-Type: text/html; charset=UTF-8" ); $reply = ""; if ( isset($_POST["email_address"]) ) { $email_address = $_POST["email_address"]; $pattern = "/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i"; if ( preg_match( $pattern, $email_address ) ) { $reply = "您输入的电子邮件地址合法

\n"; $user_name = preg_replace( $pattern ,"$1", $email_address ); $domain_name = preg_replace( $pattern ,"$2", $email_address ); $reply .= "用户名:".$user_name."
\n"; $reply .= "域名:".$domain_name."
\n\n"; } else { $reply = "您输入的电子邮件地址不合法"; } } ?> 电子邮件地址验证程序

电子邮件地址验证程序

请输入电子邮件地址:
<?php echo $reply; ?>
Copy after login

以上就是为大家分享的php邮箱地址正则表达式验证,希望对大家的学习有所帮助。

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!