admin管理员组

文章数量:1389754

I'm using the jQuery Validation Plugin : /

I'm having a problem which is causing the validation to start when the user starts typing however this is not what I want. I want to the validation to start after the user leaves the text field. Here is my code:

    <input class="required email" type="text" size="26" name="usernameField" id="usernameField" /> 

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src=".validate.js"></script>
<script type="text/javascript">

  $(document).ready(function(){

         $("#usernameField").validate({
           onfocusout:false
          });


   });

</script>

I thought using the onfocusout option would work but it's still validating as the user types. What am I doing wrong?

Thanks

I'm using the jQuery Validation Plugin : http://docs.jquery./Plugins/Validation/

I'm having a problem which is causing the validation to start when the user starts typing however this is not what I want. I want to the validation to start after the user leaves the text field. Here is my code:

    <input class="required email" type="text" size="26" name="usernameField" id="usernameField" /> 

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="http://jzaefferer.github./jquery-validation/jquery.validate.js"></script>
<script type="text/javascript">

  $(document).ready(function(){

         $("#usernameField").validate({
           onfocusout:false
          });


   });

</script>

I thought using the onfocusout option would work but it's still validating as the user types. What am I doing wrong?

Thanks

Share Improve this question asked Aug 30, 2012 at 17:57 DaveDave 7833 gold badges15 silver badges25 bronze badges 2
  • The documentation says that onkeyup is true by default. If you disable this and leave onfocusout set to true, it should work. – C Dirty Commented Aug 30, 2012 at 18:02
  • As @CDirty suggested, check stackoverflow./questions/7786021/…. – Brant Olsen Commented Aug 30, 2012 at 19:06
Add a ment  | 

1 Answer 1

Reset to default 3

You can use this code to validate onblur:

jQuery

$("#Email").blur(function() 
{
 var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;  
 var emailaddress = $("#Email").val();
 if(!emailReg.test(emailaddress)) 
    $("#emailspan").html('<font color="#cc0000">Please enter valid Email address</font>');  
 else
    $("#emailspan").html('<font color="#cc0000"></font>');  
});

HTML

<h4>
<br />Email <span id="star5">*</span>
</h4>                       
<input type="text" id="Email" name="Email" maxLength="50" size="45" /><span id="emailspan" value="0"></span>

本文标签: javascriptjQuery Validate Text Field On BlurStack Overflow