php中email邮件地址验证大全集合
发布:smiling 来源: PHP粉丝网 添加日期:2014-01-07 16:00:28 浏览: 评论:0
在php中地址验证写法各种各样的,下面我来总结几种常用的email地址验证实例,最简单的是直接使用正则表达式preg_match(\"/^([a-z0-9\\+_\\-]+)(\\.[a-z0-9\\+_\\-]+)*@([a-z0-9\\-]+\\.)+[a-z]{2,6}$/ix来验证了。
CodeIgniter框架邮件地址验证,代码如下:
- /**
- * Valid Email
- *
- * @access public
- * @param string
- * @return bool
- */
- function valid_email($str)
- {
- return ( ! preg_match("/^([a-z0-9+_-]+)(.[a-z0-9+_-]+)*@([a-z0-9-]+.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
- }
- PHPCMS邮件正则验证
- 代码如下 复制代码
- /**
- * 判断email格式是否正确
- * @param $email
- */
- function is_email($email) {
- return strlen($email) > 6 && preg_match("/^[w-.]+@[w-.]+(.w+)+$/", $email);
- }
WordPress邮件地址验证函数,代码如下:
- function is_email( $email, $deprecated = false ) {
- if ( ! emptyempty( $deprecated ) )
- _deprecated_argument( __FUNCTION__, '3.0' );
- // Test for the minimum length the email can be
- if ( strlen( $email ) < 3 ) {
- return apply_filters( 'is_email', false, $email, 'email_too_short' );
- }
- // Test for an @ character after the first position
- if ( strpos( $email, '@', 1 ) === false ) {
- return apply_filters( 'is_email', false, $email, 'email_no_at' );
- }
- // Split out the local and domain parts
- list( $local, $domain ) = explode( '@', $email, 2 );
- // LOCAL PART
- // Test for invalid characters
- if ( !preg_match( '/^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~.-]+$/', $local ) ) {
- return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
- }
- // DOMAIN PART
- // Test for sequences of periods
- if ( preg_match( '/.{2,}/', $domain ) ) {
- return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
- }
- // Test for leading and trailing periods and whitespace
- if ( trim( $domain, " tnrx0B." ) !== $domain ) {
- return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
- }
- // Split the domain into subs
- $subs = explode( '.', $domain );
- // Assume the domain will have at least two subs
- if ( 2 > count( $subs ) ) {
- return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
- }
- // Loop through each sub
- foreach ( $subs as $sub ) {
- // Test for leading and trailing hyphens and whitespace
- if ( trim( $sub, " tnrx0B-" ) !== $sub ) {
- return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
- }
- // Test for invalid characters
- if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
- return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
- }
- }
- // Congratulations your email made it!
- return apply_filters( 'is_email', $email, $email, null );
- }
下面分享一个自己写的实例,代码如下:
- $email = "tanklo_--vehy@yahoo.com.cn";
- function check_email($email) {
- $pattern_test = "/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i";
- return preg_match($pattern_test,$email);
- }
- echo check_email($email);
Tags: email 邮件地址 验证
- 上一篇:php 匹配字符中链接地址程序代码
- 下一篇:php如何对手机号码进行验证
相关文章
- ·用PHP来验证Email是否正确(2013-12-10)
- ·php中ip地址 email格式 电话号码正则验证(2014-01-06)
- ·Email正则表达式与URL正则表达式(2014-01-14)
- ·判断字符串emailAddr是否为合法的email格式(2014-01-20)
- ·php中邮箱email 电话等格式的验证(2014-07-18)
- ·php中网址、email、手机号码正则表达代码(2014-07-29)
- ·php email正则表达式详解(2014-07-29)
- ·php正则入门,实习email和URL验证(2014-08-15)
- ·PHP验证Email和IP地址最简单的方法(2015-04-11)
- ·php 判断是否为有效邮件地址实现代码(2013-12-27)
- ·php 验证手机号码与电话号码正则(2013-11-12)
- ·php验证用户名是否以字母开头与验证密码(2013-11-13)
- ·日期验证正则表达式(2013-12-11)
- ·php正则表达式验证邮箱(2014-01-05)
- ·PHP验证邮箱与邮箱有效性验证(2014-01-25)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)