jQuery實(shí)現(xiàn)驗(yàn)證表單密碼一致性及正則表達(dá)式驗(yàn)證郵箱、手機(jī)號(hào)的方法
本文實(shí)例講述了jQuery實(shí)現(xiàn)驗(yàn)證表單密碼一致性及正則表達(dá)式驗(yàn)證郵箱、手機(jī)號(hào)的方法。
jQuery 腳本
<script type="text/javascript"> function check_password() { if ($("#password").val() != $("#checkPWD").val()){ alert("請(qǐng)保證兩次輸入密碼的一致性!"); $("#checkPWD").focus(); } } function check_email() { var reg = /\w+[@]{1}\w+[.]\w+/; if (!reg.test($("#email").val())){ alert("請(qǐng)輸入正確的email!"); $("#email").focus(); } } function check_phone() { var reg = /^1[34578]\d{9}$/; if (!reg.test($("#phone").val())){ alert("請(qǐng)輸入正確的手機(jī)號(hào)!"); $("#phone").focus(); } } </script>
html 文件
<!DOCTYPE html> <html> <head> <script src="jquery1.3.2.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>注冊(cè)界面</title> </head> <body> <center> <h1>用戶注冊(cè)</h1> <form action="" method="post"> <table width="400px" cellspacing="0px" cellpadding="0px" border="1px"> <tr> <td>用戶名</td> <td><input type="text" name="username" placeholder="用戶名為3-12位字母數(shù)字或下劃線組合" ></td> </tr> <tr> <td>密 碼</td> <td><input type="password" name="password" placeholder="密碼長(zhǎng)度為6-12位的純數(shù)字" id="password"></td> </tr> <tr> <td>確認(rèn)密碼</td> <td><input type="password" name="checkPWD" placeholder="密碼長(zhǎng)度為6-12位的純數(shù)字" id="checkPWD" onchange="check_password()"></td> </tr> <tr> <td>手機(jī)號(hào)碼</td> <td><input type="text" name="phone" placeholder="請(qǐng)輸入正確的手機(jī)號(hào)碼格式" id="phone" onchange="check_phone()"></td> </tr> <tr> <td>郵箱</td> <td><input type="email" name="email" placeholder="請(qǐng)輸入正確郵箱格式" id="email" onchange="check_email()" required="required"></td> </tr> <tr> <td colspan="2" style="text-align:center"> <input type="submit" value="注冊(cè)"> <input type="reset" value="重置"> </td> </tr> </table> </form> </center> </body> </html>
運(yùn)行結(jié)果:
PS:這里再為大家提供2款非常方便的正則表達(dá)式工具供大家參考使用:
JavaScript正則表達(dá)式在線測(cè)試工具:
http://tools.jb51.net/regex/javascript
正則表達(dá)式在線生成工具:
http://tools.jb51.net/regex/create_reg
更多關(guān)于jQuery相關(guān)內(nèi)容可查看本站專題:《jQuery正則表達(dá)式用法總結(jié)》、《jQuery字符串操作技巧總結(jié)》、《jQuery操作xml技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jquery選擇器用法總結(jié)》及《jQuery常用插件及用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
相關(guān)文章
jquery實(shí)現(xiàn)點(diǎn)擊文字可編輯并修改保存至數(shù)據(jù)庫(kù)
網(wǎng)上的方法只有點(diǎn)擊文字編輯并保持,但是沒有完整的代碼寫怎么保存到數(shù)據(jù)庫(kù),本例用一條sql語句保存到數(shù)據(jù)庫(kù)2014-04-04jquery對(duì)象和javascript對(duì)象即DOM對(duì)象相互轉(zhuǎn)換
對(duì)于已經(jīng)是一個(gè) DOM 對(duì)象,只需要用 $() 把DOM對(duì)象包裝起來,就可以獲得一個(gè) jQuery 對(duì)象了,使用[index]和.get(index)可以轉(zhuǎn)為DOM對(duì)象2014-08-08jQuery向webApi提交post json數(shù)據(jù)
這篇文章主要介紹了jQuery向webApi提交post json數(shù)據(jù)的方法,非常不錯(cuò),需要的的朋友參考下2017-01-01jQuery簡(jiǎn)單實(shí)現(xiàn)列表隱藏和顯示效果示例
這篇文章主要介紹了jQuery簡(jiǎn)單實(shí)現(xiàn)列表隱藏和顯示效果,結(jié)合實(shí)例形式分析了jQuery中slideToggle動(dòng)態(tài)操作頁(yè)面元素切換的相關(guān)技巧,需要的朋友可以參考下2016-09-09jQuery+Datatables實(shí)現(xiàn)表格批量刪除功能【推薦】
這篇文章主要介紹了jQuery+Datatables實(shí)現(xiàn)表格批量刪除功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10jQuery1.9.1源碼分析系列(十六)ajax之a(chǎn)jax框架
這篇文章主要介紹了jQuery1.9.1源碼分析系列(十六)ajax之a(chǎn)jax框架 的相關(guān)資料,需要的朋友可以參考下2015-12-12基于jQuery Bar Indicator 插件實(shí)現(xiàn)進(jìn)度條展示效果
這篇文章主要介紹了基于jQuery Bar Indicator 插件實(shí)現(xiàn)進(jìn)度條展示效果的相關(guān)資料,需要的朋友可以參考下2015-09-09jquery lazyload延遲加載技術(shù)的實(shí)現(xiàn)原理分析
懶加載技術(shù)(簡(jiǎn)稱lazyload)并不是新技術(shù),它是js程序員對(duì)網(wǎng)頁(yè)性能優(yōu)化的一種方案。lazyload的核心是按需加載。在大型網(wǎng)站中都有l(wèi)azyload的身影,例如谷歌的圖片搜索頁(yè),迅雷首頁(yè),淘寶網(wǎng),QQ空間等。2011-01-01