There is a question with the same subject, but it dont have a conclusive answer.
I have a bunch of inputs with variable names generated by an add jquery function, and i need to validate those fields (if they exist).
Can i use the validate plugin with the class instead of the name? or something?
Here is my code:
//add function
$(document).ready(function(){
var i = $('input').size() +1;
$('#add').click(function(event) {
event.preventDefault();
$('.table1').before('<table class="new_table">
'<tr>' +
'<td colspan="4" class="subTitle_bar">' +
'<spring:message code="phoneTable" /> '+ i +' '+
'</td>' +
'</tr>' +
'<tr>' +
'<td class="item">' +
'<spring:message code="phoneNumber" />' +
'<span class="required">*</span>' +
'</td>' +
'<td colspan="3">' +
'<input type="text" id="phone1' + i + '" name="phone1' + i + '" class="requiredField phone" />' +
'</td>' +
'</tr>');
i++;
});
And the validate:
$(document).ready(function () {
$("#contactForm").validate({
//rules
rules:{
phone1:{ required: true },
How can i validate the phone, if i dont know his field name yet?
Can somebody help me?