郵箱、手機號、中文 js跟php正則驗證

來源:互聯網
上載者:User

標籤:style   blog   http   color   ar   sp   div   on   log   

郵箱正則:

jS:

1 var regEmail = /^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;2 //驗證3 if(regEmail.test(email)){4     alert("success");      5 }

PHP:

1 $regEmail = "/^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/";2 if(preg_match($regEmail, $email){3     echo ‘success‘;4 }    

 

手機號正則:

JS:

1 var regPhone = /^1[3|4|5|8][0-9]\d{4,8}$/;2 if(regPhone.test(phone)){3     alert("success");  4 }

PHP:

1 $regPhone = "/^1[3|4|5|8][0-9]\d{4,8}$/";2 if(preg_match($regPhone, $phone){3     echo ‘success‘; 4 } 

 

 

中文驗證:

JS:

1 var regZn = /^[\u4e00-\u9fa5]{2,}$/;2 if(regZn.test(zn)){3    alert("success");  4 }

PHP:(詳情見:http://blog.sina.com.cn/s/blog_69e1a96d0100vebg.html)

1 $regZn = "/^[\x{4e00}-\x{9fa5}]{2,}$/u";2 if(preg_match($regZn, $zn)){3      echo ‘success‘;4 }

 

如需同時驗證字元是否為郵箱或手機號,則可:

/(^([a-zA-Z0-9_-])[email protected]([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+)|(^1[3|4|5|8][0-9]\d{4,8}$)/

 

郵箱、手機號、中文 js跟php正則驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.