jsRegex的使用姿勢

來源:互聯網
上載者:User

標籤:js驗證   doctype   com   需要   html   教程   common   class   運算式   

 1 <!DOCTYPE html> 2 <html> 3  4     <head> 5         <meta charset="UTF-8"> 6         <title></title> 7         <!--1.引入jq庫--> 8         <script type="text/javascript" src="../js/common/jquery.js"></script> 9     </head>10     <!--2.html代碼-->11     <input type="text" name="" id="phone" value="" placeholder="請輸入需要驗證的資料" />12     <input type="button" name="pp" id="pp" value="驗證" />13 14     <body>15         <script type="text/javascript">16             //3.js代碼17             $("#pp").on("click", function() {18                 var phone = $("#phone").val();19                 //4.Regex輸入20                 var num = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;21                 if(phone.length == 0) {22                     alert("輸入不可為空");23                 } else if(!(num.test(phone))) {24                     alert("輸入不正確");25                 } else {26                     alert("輸入正確");27                 }28             })29             //5.下面是一些常用的Regex30             //手機號碼驗證31             var phone = /^1[34578]\d{9}$/;32             //社會安全號碼碼驗證33             var isIDCard = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;34             var isIDCard2 = /^(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)$/;35             //E-mail驗證36             var e_mail= /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;37             //數字驗證38             var Number = /^[0-9]*$/;39         </script>    40     </body>41 42 </html>

上面代碼只是一個簡單的正則使用,js驗證這塊已經足夠使用了。

菜鳥教程正則地址:https://c.runoob.com/front-end/854。

在這裡推薦新手使用菜鳥教程(http://www.runoob.com/),這是新手進入代碼世界的一個好網站。

其實做什麼事情都一樣,代碼也一樣,只有一步一步理解透了,我們才能在編程這塊遊刃有餘。

 

jsRegex的使用姿勢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.