[jQuery]Validation配合驗證碼(Captcha)

Validation若要即時驗證Captcha需要使用額外的Method
剛好自己要用到
就整理一下供大家和自己參考

先看一下,html碼的部分
<img src="code_num.php" id="getcode_num" title="Refresh Captcha" align="absmiddle" />
<input name="code_num" id="code_num" type="text" />

再來jQuery的部分
$(document).ready(function() {
   $.validator.addMethod('checkCaptcha', function() {
    var bfr = false;
     var code = $('#code_num').val();
     var phpquery = $.ajax({url:'chk_code.php',
       type: 'POST',
       async: false,
       data:'act=num&code=' + code,
       success:function(resp) {
         if (resp == 'true') {
           bfr = true;
         }
       }
     });
   if(bfr){
      return true;
    } else {
     $('#getcode_num').attr('src','code_num.php?' + Math.random());
     return false;
    }
   },'');
   $('#sendFrm').validate({
     onkeyup: false,
     rules:{
        code_num: {
          required: true,
          checkCaptcha: true
        }
     },
     messages:{
        code_num:{
         checkCaptcha: 'Your Captcha response was incorrect. Please try again.'
        }
     }
  });
});
簡單說明一下
就是先增加一個Method(checkCaptcha)
這個Method目的是即時檢查驗證碼
而輸入錯誤的話,就再次更新驗證碼
所以後端也要有一支程式去比對驗證碼
 如果不需即時驗證的話,那其實就用不到這方法了

在驗證時,就要把這Method代入
其它都算基本的格式
引用通告地址: http://www.fase.idv.tw/blog/trackback.php?tbID=122&extra=47bea0
標籤: jQuery
評論: 0 | 引用: 125 | 閱讀: 98103
car accident lawyer omaha [2019-01-10 15:53 ]
標題: car accident lawyer omaha
連結: https://www.destructoid.com/?name=lincolncarinjuryattorney&a=444080&start=0&chaos=ok&
摘要: Get today the top professional motorcycle accident attorney currently present for you now!
social media strategy [2019-01-02 12:11 ]
標題: social media strategy
連結: https://www.destructoid.com/?name=omahaseoexpert&a=442631&start=0&chaos=ok&who=me
摘要: Get going now with the best site optimization that will be available in addition provides a good ROI today!
local seo outsource [2018-12-30 03:52 ]
標題: local seo outsource
連結: https://www.destructoid.com/?name=seooutsourcesd&a=442533&start=0&chaos=ok&who=me
摘要: Find a top seo company currently now available and on sale now only!
outsource seo services [2018-12-29 13:46 ]
標題: outsource seo services
連結: https://www.destructoid.com/?name=seooutsourcesd&a=442533&start=0&chaos=ok&who=me
摘要: Find the best outsource seo services that is now available in addition at good rates now only!
metal clock dials [2018-12-27 19:43 ]
標題: metal clock dials
連結: https://www.tapatalk.com/groups/clockpartsagency/viewtopic.php?f=2&t=2
摘要: Get today the highest quality Clock kit parts that is available and in stock today and are at the best price today only!
DIY clock dials repair [2018-12-18 08:42 ]
標題: DIY clock dials repair
連結: https://www.tapatalk.com/groups/clockpartskit/viewtopic.php?f=2&t=2
摘要: Buy today best available replacement clock parts that's available and in stock today and are at great prices today only!
brass fire pit burners [2018-12-10 02:18 ]
標題: brass fire pit burners
連結: https://www.fark.com/users?login=gasfirepits&togglehtml=1&undefined=View&is_using_js=1
摘要: Get today a great Warming trends fire pit kit currently available and now in stock and at a great price this week only!
bozeman seo company [2018-12-09 15:46 ]
標題: bozeman seo company
連結: https://www.destructoid.com/?name=whitefishseo&a=441439&start=0&chaos=ok&who=me
摘要: Get Services From the wonderful seo services agency that is currently available and at great prices today!
mechanism for clocks [2018-11-29 09:33 ]
標題: mechanism for clocks
連結: https://www.tapatalk.com/groups/motorclockparts/viewtopic.php?f=2&t=2
摘要: Get top quality replacement parts for battery operated clocks that are available and in stock now and on sale get it now, today only!
clock Hands Repair [2018-11-28 03:47 ]
標題: clock Hands Repair
連結: https://www.tapatalk.com/groups/motorclockparts/viewtopic.php?f=2&t=2
摘要: Purchase the best quality clock parts that are available and now available and reasonably priced get it now, today only!
發表評論
暱 稱(*): 密 碼:
網 址: E - mail:
驗證碼(*): 驗證碼圖片
請用滑鼠點選輸入
選 項:
頭 像:
內 容(*):