国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php中email郵件地址驗證大全集合

2024-09-04 11:47:12
字體:
來源:轉載
供稿:網友

在php中地址驗證寫法各種各樣的,下面我來總結幾種常用的email地址驗證實例,最簡單的是直接使用正則表達式preg_match(/"/^([a-z0-9//+_//-]+)(//.[a-z0-9//+_//-]+)*@([a-z0-9//-]+//.)+[a-z]{2,6}$/ix來驗證了。

CodeIgniter框架郵件地址驗證,代碼如下:

  1. /**  
  2.      * Valid Email  
  3.      *  
  4.      * @access  public  
  5.      * @param   string  
  6.      * @return  bool  
  7.      */ 
  8.     function valid_email($str)  
  9.     {  
  10.         return ( ! preg_match("/^([a-z0-9+_-]+)(.[a-z0-9+_-]+)*@([a-z0-9-]+.)+[a-z]{2,6}$/ix"$str)) ? FALSE : TRUE;  
  11.     } 
  12. PHPCMS郵件正則驗證 
  13.  代碼如下 復制代碼 
  14. /**  
  15.  * 判斷email格式是否正確  
  16.  * @param $email  
  17.  */ 
  18. function is_email($email) {  
  19.     return strlen($email) > 6 && preg_match("/^[w-.]+@[w-.]+(.w+)+$/"$email);  

WordPress郵件地址驗證函數,代碼如下:

  1. function is_email( $email$deprecated = false ) {  
  2.     if ( ! emptyempty$deprecated ) )  
  3.         _deprecated_argument( __FUNCTION__'3.0' );  
  4.    
  5.     // Test for the minimum length the email can be  
  6.     if ( strlen$email ) < 3 ) {  
  7.         return apply_filters( 'is_email', false, $email'email_too_short' );  
  8.     }  
  9.    
  10.     // Test for an @ character after the first position  
  11.     if ( strpos$email'@', 1 ) === false ) {  
  12.         return apply_filters( 'is_email', false, $email'email_no_at' );  
  13.     }  
  14.    
  15.     // Split out the local and domain parts  
  16.     list( $local$domain ) = explode'@'$email, 2 );  
  17.    
  18.     // LOCAL PART  
  19.     // Test for invalid characters  
  20.     if ( !preg_match( '/^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~.-]+$/', $local ) ) {  
  21.         return apply_filters( 'is_email', false, $email'local_invalid_chars' );  
  22.     }  
  23.    
  24.     // DOMAIN PART  
  25.     // Test for sequences of periods  
  26.     if ( preg_match( '/.{2,}/'$domain ) ) {  
  27.         return apply_filters( 'is_email', false, $email'domain_period_sequence' );  
  28.     }  
  29.    
  30.     // Test for leading and trailing periods and whitespace  
  31.     if ( trim( $domain" tnrx0B." ) !== $domain ) {  
  32.         return apply_filters( 'is_email', false, $email'domain_period_limits' );  
  33.     }  
  34.    
  35.     // Split the domain into subs  
  36.     $subs = explode'.'$domain );  
  37.    
  38.     // Assume the domain will have at least two subs  
  39.     if ( 2 > count$subs ) ) {  
  40.         return apply_filters( 'is_email', false, $email'domain_no_periods' );  
  41.     }  
  42.    
  43.     // Loop through each sub  
  44.     foreach ( $subs as $sub ) {  
  45.         // Test for leading and trailing hyphens and whitespace  
  46.         if ( trim( $sub" tnrx0B-" ) !== $sub ) {  
  47.             return apply_filters( 'is_email', false, $email'sub_hyphen_limits' );  
  48.         }  
  49.    
  50.         // Test for invalid characters  
  51.         if ( !preg_match('/^[a-z0-9-]+$/i'$sub ) ) {  
  52.             return apply_filters( 'is_email', false, $email'sub_invalid_chars' );  
  53.         }  
  54.     }  
  55.    
  56.     // Congratulations your email made it!  
  57.     return apply_filters( 'is_email'$email$email, null );  

下面分享一個自己寫的實例,代碼如下:

  1. $email = "tanklo_--vehy@yahoo.com.cn"
  2.     function check_email($email) { 
  3.        $pattern_test = "/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i"
  4.        return  preg_match($pattern_test,$email); 
  5.     } 
  6. echo check_email($email);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 白河县| 同心县| 武夷山市| 大邑县| 锦屏县| 红安县| 隆德县| 土默特右旗| 邵武市| 剑河县| 仙桃市| 晋江市| 武定县| 赤峰市| 汕头市| 东乡县| 灵宝市| 黑水县| 延庆县| 贡山| 霸州市| 鄂托克前旗| 江陵县| 吴旗县| 长白| 营山县| 东乡县| 东至县| 汉阴县| 缙云县| 古交市| 黄山市| 施秉县| 措美县| 禄丰县| 万安县| 绥德县| 新乡县| 崇文区| 府谷县| 莫力|