标签:regexp hasclass last input var his val put move
1 <script src="jquery.js"></script> 2 <script>
//函数正则验证空字符和 空白键(半/圆角) 3 function isNull(str){ 4 if ( str == "" ) return true; 5 var regu = "^[ | ]+$"; 6 var re = new RegExp(regu); 7 return re.test(str); 8 } 9 10 function check(){ 11 var lname = $("#last_name"); 12 if(lname.val()=="姓名" || isNull($("#last_name").val())){ 13 lname.addClass(‘rborder‘); 14 lname.focus(); 15 return false; 16 } 17 18 if($("#mobile").val()=="手机号码" || isNull($("#mobile").val())){ 19 $("#mobile").addClass(‘rborder‘); 20 $("#mobile").focus(); 21 return false; 22 } 23 24 var email = $(‘#email‘).val(); 25 var reg = /\w+[@]{1}\w+[.]\w+/; 26 if(reg.test(email)){ 27 if($(‘#email‘).hasClass(‘rborder‘)){ 28 $(‘#email‘).removeClass(‘rborder‘); 29 } 30 }else{ 31 $(‘#email‘).addClass(‘rborder‘); 32 $(‘#email‘).focus(); 33 return false; 34 } 35 } 37 38 $(function(){ 39 $(‘#last_name‘).blur(function(){ 40 if($("#last_name").val()=="姓名" || isNull($("#last_name").val())){ 41 $(this).addClass(‘rborder‘); 42 }else{ 43 if($("#last_name").hasClass(‘rborder‘)){ 44 $("#last_name").removeClass(‘rborder‘); 45 } 46 } 47 }); 48 49 $(‘#mobile‘).blur(function(){ 50 if($("#mobile").val()=="手机号码" || isNull($("#mobile").val())){ 51 $(this).addClass(‘rborder‘); 52 }else{ 53 if($(this).hasClass(‘rborder‘)){ 54 $(this).removeClass(‘rborder‘); 55 } 56 } 57 }); 58 59 $(‘#email‘).blur(function(){ 60 var email = $(this).val(); 61 var reg = /\w+[@]{1}\w+[.]\w+/; 62 if(reg.test(email)){ 63 if($(this).hasClass(‘rborder‘)){ 64 $(this).removeClass(‘rborder‘); 65 } 66 }else{ 67 $(this).addClass(‘rborder‘); 68 } 69 }); 70 71 }) 72 </script>
<input class="button" name="submit" type="submit" value="确认提交" onclick="return check()" />
标签:regexp hasclass last input var his val put move
原文地址:http://www.cnblogs.com/lola/p/6053733.html