I’m trying to validate my inputs with jQuery before a form is sent.
This is what my input fields look like when there is no value inserted in the database:
<input
class="field"
type="text"
style="background-color: rgb(255, 255, 255);"
value="" name="input_18748_388_1257894000_"/>
This is what my input fields look like when there is an existing value inserted in the database:
<input
class="field"
type="text"
style="background-color: rgb(255, 255, 255);"
value=""
name="input_18748_388_1257894000_46549876"/>
I would like to:
-
Check if the value is already in the database
-
Check if the user want to replace an
existing value by nothing or zero and
disallow it. -
Check if the user is trying to
insert 0 in a new field and
disallow it.
Solved:
$("input[name^='input_"+var+"_']")
.each(function() {
if ($(this).attr('name').match(/^input_\d+_\d+_\d+_\d+/)
&& ($(this).val() == '' || $(this).val() <= 0))
{
displayDialog("<?=_('error')?>")
flag_error = 1;
return false;
}
});
// Submit the form.
1 Answer