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

使用正則表達(dá)式驗(yàn)證登錄頁(yè)面輸入是否符合要求

 更新時(shí)間:2017年09月07日 16:11:34   作者:煙花盛典  
這篇文章主要介紹了使用正則表達(dá)式驗(yàn)證登錄頁(yè)面輸入是否符合要求的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

先給大家展示下效果圖:

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:

<!DOCTYPE html>
<html>
 <head>
 <meta charset="UTF-8">
 <title></title>
 </head>
 <script src="js/jquery-1.8.0.min.js"></script>
 <script>
 $(function() {
  $("input[name='uname']").blur(function() { //失去焦點(diǎn)
  var namestr = $(this).val();
  var regstr = /^[\u4e00-\u9fa5]{2,4}$/;
  if(!regstr.test(namestr)) {
   $(this).parent().next().html("用戶名必須是2-4個(gè)漢字").css("color", "red");
   return false;
  }
  return true;
  }); 
  $("input[name = 'uname']").focus(function() { //獲取焦點(diǎn)
  $(this).val("");
  $(this).parent().next().html("");
  });
  $("input[name='pwd']").blur(function() {
  var pwdstr = $(this).val();
  var regstr = /^\w{6}$/;
  if(!regstr.test(pwdstr)) {
   $(this).parent().next().html("密碼必須是6位數(shù)字字母下劃線").css("color", "red");
   return false;
  }
  return true;
  });
  $("input[name='pwd']").focus(function() {
  $(this).parent().next().html("");
  });
  $("input[name='birthday']").blur(function() {
  var birthdaystr = $(this).val();
  var regstr = /^(19|20)\d{2}-(1[0-2]|0?[1-9])-(3[0-1]|2[0-9]|0?[1-9])$/;
  if(!regstr.test(birthdaystr)) {
   $(this).parent().next().html("日期格式不正確").css("color", "red");
   return false;
  }
  return true;
  });
  $("input[name='birthday']").focus(function() {
  $(this).parent().next().html("");
  });
  $("input[name='email']").blur(function(){
  var emailstr = $(this).val();
  var regstr = /^[\w\-]+@[a-z0-9A-Z]+(\.[a-zA-Z]{2,3}){1,2}$/;
  if(!regstr.test(emailstr)){
   $(this).parent().next().html("郵箱格式不正確").css("color","red");
   return false;
  }
  return true;
  });
  $("input[name='email']").focus(function(){
  $(this).parent().next().html("");
  });
 });
 </script>
 <style>
 body {
  font-size: 12px;
 }
 #home {
  background-color: beige;
  border: solid 1px black;
  width: 550px;
  height: 185px;
  margin: auto;
  margin-top: 20px;
 }
 #head {
  height: 135px;
 }
 #foot {
  text-align: center;
 }
 .dl1 {
  clear: both;
  padding-left: 10px;
 }
 .dl1 dt {
  float: left;
  height: 30px;
  width: 80px;
  line-height: 30px;
 }
 .dl1 dd {
  float: left;
  height: 30px;
  line-height: 30px;
  /*width: 250px;*/
 }
 #btn_res {
  background-image: url(img/reset.gif);
  width: 80px;
  height: 34px;
 }
 #btn_sub {
  background-image: url(img/submit.gif);
  width: 80px;
  height: 34px;
 }
 </style>
 <body>
 <div id="home">
  <div id="head">
  <form action="" method="post">
   <dl class="dl1">
   <dt>用戶名 : </dt>
   <dd class="dd1"><input type="text" value="輸入用戶名" name="uname" /></dd>
   <dd></dd>
   </dl>
   <dl class="dl1">
   <dt>用戶密碼 : </dt>
   <dd class="dd1"><input type="password" name="pwd" /></dd>
   <dd></dd>
   </dl>
   <dl class="dl1">
   <dt>出生日期 : </dt>
   <dd class="dd1"><input type="text" name="birthday" /></dd>
   <dd>yyyy-mm-dd</dd>
   </dl>
   <dl class="dl1">
   <dt>用戶郵箱 : </dt>
   <dd><input type="text" name="email"/></dd>
   <dd></dd>
   </dl>
  </form>
  </div>
  <div id="foot">
  <input type="submit" value="" id="btn_sub" />
  <input type="reset" value="" id="btn_res" />
  </div>
 </div>
 </body>
</html>

總結(jié)

以上所述是小編給大家介紹的使用正則表達(dá)式驗(yàn)證登錄頁(yè)面輸入是否符合要求,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Python正則表達(dá)式的7個(gè)使用典范(推薦)

    Python正則表達(dá)式的7個(gè)使用典范(推薦)

    這篇文章主要介紹了Python正則表達(dá)式的7個(gè)使用典范,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-11-11
  • grep中使用

    grep中使用"\d"匹配數(shù)字不成功的原因解決

    這篇文章主要介紹了grep中使用"\d"匹配數(shù)字不成功的原因解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • PHP中正則表達(dá)式對(duì)UNICODE字符碼的匹配方法

    PHP中正則表達(dá)式對(duì)UNICODE字符碼的匹配方法

    看到標(biāo)題是“請(qǐng)教PHP 一個(gè)正則匹配的問題”,又是正則表達(dá)式,好吧,看下,誰讓俺比較喜歡鼓搗正則呢。下面開始正題。
    2011-04-04
  • 使用正則表達(dá)式判斷密碼強(qiáng)弱

    使用正則表達(dá)式判斷密碼強(qiáng)弱

    本文給大家分享使用正則表達(dá)式來判斷密碼強(qiáng)弱的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2017-06-06
  • 淺析正則表達(dá)式

    淺析正則表達(dá)式

    所謂的正則表達(dá)式,就是用一類元字符(不表示本身意義,而表示統(tǒng)配或其他意義),組合其他字符所編數(shù)出來的,能夠匹配符合條件的字符
    2013-09-09
  • 常用正則表達(dá)式匹配代碼介紹

    常用正則表達(dá)式匹配代碼介紹

    這篇文章主要介紹了常用正則表達(dá)式匹配代碼介紹方法的相關(guān)資料,需要的朋友可以參考下
    2016-07-07
  • 實(shí)例代碼詳解正則表達(dá)式匹配換行

    實(shí)例代碼詳解正則表達(dá)式匹配換行

    在javascript中,使用正則表達(dá)式匹配換行可能會(huì)遇到各種問題,下面就通過實(shí)例介紹一下如何實(shí)現(xiàn)此功能,對(duì)正則表達(dá)式匹配換行相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2015-12-12
  • 正則表達(dá)式實(shí)現(xiàn)字符串每4位后自動(dòng)加空格效果(兩種方法)

    正則表達(dá)式實(shí)現(xiàn)字符串每4位后自動(dòng)加空格效果(兩種方法)

    本文通過兩種方法給大家介紹了正則表達(dá)式實(shí)現(xiàn)字符串每4位后自動(dòng)加空格效果,需要的朋友可以參考下
    2018-09-09
  • 史上最全的PHP正則表達(dá)式(手機(jī)號(hào)需要加上177-***)

    史上最全的PHP正則表達(dá)式(手機(jī)號(hào)需要加上177-***)

    正則表達(dá)式,大家在開發(fā)中應(yīng)該是經(jīng)常用到,現(xiàn)在很多開發(fā)語言都有正則表達(dá)式的應(yīng)用,比如javascript,java,.net,php等等,今天給大家介紹史上最全的PHP正則表達(dá)式(手機(jī)號(hào)需要加上177-***),一起看看吧
    2017-10-10
  • VsCode中常用的一些正則表達(dá)式操作方法

    VsCode中常用的一些正則表達(dá)式操作方法

    正則真的好用,平時(shí)工作用正則最多的地方就是在編輯器里做查找替換,之前系統(tǒng)學(xué)習(xí)了一段時(shí)間的正則但有些技巧長(zhǎng)時(shí)間不用有些生疏了,這篇文章主要給大家介紹了關(guān)于VsCode中常用的一些正則表達(dá)式操作方法,需要的朋友可以參考下
    2024-05-05

最新評(píng)論