js指令碼輸入控制總結

來源:互聯網
上載者:User

標籤:io   ar   os   使用   sp   java   for   on   div   

  1.檢測使用者名稱只能由中英文、數字及底線組成,不能使用其他符號,使用者名稱是否已經存在

function checkLoginAccount() {
  var msg = ‘‘;
  var nameid1 = document.getElementById("login_name").value;
  if (nameid1.length < 4 || nameid1.length > 20) {
    msg = "使用者名稱長度只能在4-20位字元之間";
    alert(msg);
    return false;
  }
  else {
    for (var index = 0; index < nameid1.length; index++) {
    c = nameid1.charAt(index);
    c = c.toUpperCase();
    if (!((c >= "A" && c <= "Z") || (c >= "0" && c <= "9") || c == "_"||c>="\u4e00"&&c<="\u9fa5")) {
      msg = "使用者名稱只能由中英文、數字及底線組成,不能使用其他符號";
      alert(msg);
      return false;
    }
  }
}
  var params = {loginName: $(‘#login_name‘).val()};
  $.post("UserRegisterCheckLoginName", params, function (data) {  //使用者名稱是否已經存在
    if (data.result == "error") {
    retVal = false;
    msg = "該帳號已存在,請修改";
    alert(msg);
    // document.getElementById("regNameHint").innerHTML = msg;//此句表示在頁面某個地方顯示出來,一般是檢測輸入框後面,但要定義div或者其他,id        //為regNameHint
    } else if (data.result == "success") {
  retVal = true;
  }
  }, "json");
r  eturn retVal;
}

  2.檢測輸入的密碼兩次輸入密碼是否一致,是否符合規格

  function checkPassword() {
    var userpwd = document.getElementById("pwd").value;
    var pwdRepeat = document.getElementById("rpwd").value;
    if (userpwd.length < 6 || userpwd.length > 20)
    {
    msg = "密碼長度6-20個字元,請重新輸入";
    alert(msg);
    return false;
    } else {
    if (userpwd !== pwdRepeat) {
    msg = "與第一次輸入的密碼不匹配!";
    alert(msg);
    return false;
  }
  else {
  return true;
  }
  }
}

  3.檢測輸入手機號碼是否符合要求

  function checkphone() {
    var link_phone = document.getElementById("link_phone").value;
    if (link_phone.length != 11) {
    msg = "手機號碼格式不正確,請重新輸入";
    alert(msg);
    return false;
  }
    for (var index = 0; index < link_phone.length; index++) {
      c = link_phone.charAt(index);
      if (!(c >= "0" && c <= "9")) {
      msg = "手機號碼格式不正確,請重新輸入";
      alert(msg);
      return false;
    }
}

    return true;
}

註:上面使用前需要引入 <script src="xx/jquery.js" type="text/javascript"></script>//xx為相對路徑

js指令碼輸入控制總結

聯繫我們

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