How can we validate the below code ? I want validate the input named software_name not be null. how to write the code? the validation rules looks only support single input.
<input name="software_name[]" type="text" class="input_txt_l software-name" value="" />
<input name="software_name[]" type="text" class="input_txt_l software-name" value="" />
<input name="software_name[]" type="text" class="input_txt_l software-name" value="" />
<input name="software_name[]" type="text" class="input_txt_l software-name" value="" />
============================update at 2011/07/26========================
I can't understand your help, I think I explain not clearly.try again.
I use this validation for form validate. http://bassistance.de/jquery-plugins/jquery-plugin-validation/
when we validate single input , we can use this to validate the name element. html code:
<form action="url/saved" method="post" id="server-form">
Name:<input name="name" type="text" class="input_txt" value=""/>
</form>
javascript code:
var v = $('#server-form').validate({
rules:{
name:{
required:true,
minlength:2,
maxlength:64
}
},
messages:{
name:{
required:'can not be null',
minlength:"too short",
maxlength:"too long"
}
},
onfocusout: function(element) {
if ( !this.checkable(element)) {
this.element(element);
}
},
errorPlacement: function(error, element) {
$(element).setValidateError({
errorBox:error
});
},
success: function(element) {
$(element).setValidateOK();
}
});
but when we use form array. like this
<input name="software_name[]" type="text" class="input_txt_l software-name" value="" />
the jquery-validation-plugin looks not support . Am I right?
the only way looks likes @rharshath said ?
$('.software-name').each(function(i, $input) {
if( $.trim($input.val()) == "" ) {
// go nuts - alert it, or highlight that field,
// or put a tooltip beside it - whatever.
}
});
we have to hack it by myself ?