I have 3 fields I want to validate validate all 3 fields and allow the form to be submitted if a minimum of one field is filled. I am unable to do that.
Please check my code:
<script type="text/javascript">
$(function(){
$("#field1").validate({
expression: "if (VAL) return true; else return false;",
message: "Please enter username!",
});
$("#field2").validate({
expression: "if (VAL) return true; else return false;",
message: "Please enter username!",
});
$("#field3").validate({
expression: "if (VAL) return true; else return false;",
message: "Please enter username!",
});
});
</script>
HTML-
<form>
<input type="text" id="field1" /> <!-- username1 -->
<input type="text" id="field2" /> <!-- username2 -->
<input type="text" id="field3" /> <!-- username3 -->
<input type="submit id="submit" value="Submit" />
</form>
In the above code, the validation requires all fields to be filled. But my requirement is only one field needs to be filled. If I leave all fields, then the message "Please enter username!" will show.
.validate()a plugin or your own method? Perhaps you can set this up as a jsFiddle? - Moobjquery.validate.jsandjquery.validation.functions.js- Developernameor class?$("input[name='username']").validate({.... WHY do you have 3 fields for the same thing anyway!? - Moob$("input[type=text]").each(function(){ if($(this).val().length > 0) alert('user has inputted'); }). For checking you can store the lengths in a array and check if any value is greater than 0 then proceed for submit else show message :) - D.T.