Confirm (in terms of an empty field) any one of the two fields in jquery-1.9.1.min

I want to check (do not allow blank) any field of these two! Got some idea from here , but couldn't implement it in version 1.9.1.

Even both fields are checked, which is also excellent. Any inputs ..... guys

Here is my jquery

jQuery.validator.addMethod("require_from_group", function(value, element, options) { alert("xxx"); var valid = $(options[1], element.form).filter(function() { return $(this).val(); }).length >= options[0]; if(!$(element).data('reval')) { var fields = $(options[1], element.form); fields.data('reval', true).valid(); fields.data('reval', false); } return valid; }, jQuery.format("'Please enter either username/ email address to recover password'/Please fill out at least {0} of these fields.")); $("#forgot_pass_form").validate({ rules: { uname: { require_from_group: [1,".send_username"] }, email: { require_from_group: [1,".send_password"] } } }); 

and here is my html

 <form action="#" class="send_form" id="forgot_pass_form" method="POST"> <fieldset> <div class="send_row"> <label class="padding-top10">Email</label> <input type="text" class="send_email" id="email" name="email" /> <em>You need to type an email address</em> </div> <div class="send_row option">OR</div> <div class="send_row"> <label class="padding-top10">Username</label> <input type="text" class="send_username" id="uname" name="uname" /> </div> <div class="send_row send_submitforgotuser"> <input type="submit" value="Submit" /> </div> </fieldset> </form> 

I want to just check any field from these two empty fields.

0
source share
1 answer

Add a minlength property for each entry. If you add minlength 1, they cannot be empty. If you add the email class, it will check the email address.

HTML

 <form action="#" class="send_form" id="forgot_pass_form" method="POST"> <fieldset> <div class="send_row"> <label class="padding-top10">Email</label> <input type="text" class="send_email email" id="email" name="email" /> <em>You need to type an email address</em> </div> <div class="send_row option">OR</div> <div class="send_row"> <label class="padding-top10">Username</label> <input type="text" class="send_username" id="uname" name="uname" minlength="2" /> </div> <div class="send_row send_submitforgotuser"> <input type="submit" value="Submit" disabled="" /> </div> </fieldset> </form> 

JS:

 $(document).ready(function() { $("#forgot_pass_form").validate(); $("#forgot_pass_form input").on('change', function() { if ($('#forgot_pass_form').valid()) { $('#forgot_pass_form input[type="submit"]').removeAttr('disabled'); } else { $('#forgot_pass_form input[type="submit"]').attr('disabled', 'true'); } }); }); 

Example: http://jsfiddle.net/jeffshaver/K2XAX/3/

0
source

All Articles