欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery實現(xiàn)驗證表單密碼一致性及正則表達(dá)式驗證郵箱、手機(jī)號的方法

 更新時間:2017年12月05日 11:56:12   作者:HeatDeath  
這篇文章主要介紹了jQuery實現(xiàn)驗證表單密碼一致性及正則表達(dá)式驗證郵箱、手機(jī)號的方法,涉及jQuery表單元素獲取及正則驗證相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了jQuery實現(xiàn)驗證表單密碼一致性及正則表達(dá)式驗證郵箱、手機(jī)號的方法。

jQuery 腳本

<script type="text/javascript">
function check_password() {
  if ($("#password").val() != $("#checkPWD").val()){
    alert("請保證兩次輸入密碼的一致性!");
    $("#checkPWD").focus();
  }
}
function check_email() {
  var reg = /\w+[@]{1}\w+[.]\w+/;
  if (!reg.test($("#email").val())){
    alert("請輸入正確的email!");
    $("#email").focus();
  }
}
function check_phone() {
  var reg = /^1[34578]\d{9}$/;
  if (!reg.test($("#phone").val())){
    alert("請輸入正確的手機(jī)號!");
    $("#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>注冊界面</title>
</head>
<body>
  <center>
    <h1>用戶注冊</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>密&nbsp;碼</td>
          <td><input type="password" name="password" placeholder="密碼長度為6-12位的純數(shù)字" id="password"></td>
        </tr>
        <tr>
          <td>確認(rèn)密碼</td>
          <td><input type="password" name="checkPWD" placeholder="密碼長度為6-12位的純數(shù)字" id="checkPWD" onchange="check_password()"></td>
        </tr>
        <tr>
          <td>手機(jī)號碼</td>
          <td><input type="text" name="phone" placeholder="請輸入正確的手機(jī)號碼格式" id="phone" onchange="check_phone()"></td>
        </tr>
        <tr>
          <td>郵箱</td>
          <td><input type="email" name="email" placeholder="請輸入正確郵箱格式" id="email" onchange="check_email()" required="required"></td>
        </tr>
        <tr>
          <td colspan="2" style="text-align:center">
            <input type="submit" value="注冊">
            <input type="reset" value="重置">
          </td>
        </tr>
      </table>
    </form>
  </center>
</body>
</html>

運行結(jié)果:

PS:這里再為大家提供2款非常方便的正則表達(dá)式工具供大家參考使用:

JavaScript正則表達(dá)式在線測試工具:
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é)

希望本文所述對大家jQuery程序設(shè)計有所幫助。

相關(guān)文章

最新評論