Live2D

验证码二(验证码使用)

//控制器方面对比验证码内容是否与用户输入的一致即可

/*

*视图部分

*/

 1  <font style="font-size: 17px">手机号:</font>
 2 
 3 <input type="text" class="style1" id="phone" placeholder="认证手机号" maxLength="11" >
 4 
 5  
 6 
 7 <font style="font-size: 17px">验证码:</font>
 8 
 9 <input type="text" class="style1" style="width: 188px;" id="code_num" name="code_num" maxlength="6" onchange="names()" />
10 
11 <img src="checkcode/checkcode.php" id="getcode_num" title="看不清,点击换一张" align="absmiddle" />
12 
13 <span id="code2" style="color:red;text-align:left;margin-left: -8%"></span>

 

 

 

/*

*JS部分

*/

 1 //手机号正则匹配
 2 $('#phone').bind('input propertychange', function() {
 3 
 4   var sMobile = $("#phone").val();
 5 
 6   if(!(/^0?(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57])[0-9]{8}$/.test(sMobile))){ 
 7     $('#phone2').html("手机号码错误");
 8     return false; 
 9   }else{
10     $("#phone2").html("");
11     return true; 
12   }
13 
14 });
15 
16  
17 
18 //JS点击刷新验证码
19 $(function() {
20   $("#getcode_num").click(function() {
21     $(this).attr("src", 'checkcode/checkcode.php?' + Math.random());
22   });
23 });
24 
25 //验证码
26 function names()
27 {
28   var code_num=$("#code_num").val();
29   $.ajax({
30     type: "get",
31     url: "{{URL('verify')}}",
32     data: "code_num="+code_num,
33     success: function(msg){
34       if (msg == 0) {
35         $('#code2').html("验证码错误");
36         return false; 
37       }else{
38       $('#code2').html("");
39         return true;     
40       }
41     }
42    });
43 }

 

  

简单的不要不要了

posted @ 2017-04-18 18:31  韦森  阅读(264)  评论(0编辑  收藏  举报