working js fiddle :http://jsfiddle.net/dofpezeg/ This is a dynamic form where i have to apply validation.The problem i am facing is that when i click on add button new fields are created and validation doesnt run on them automatically.i have used each loop via ":input.req" where req is the class name i have given to all elements whether static or being created new. Now, in onclick i use this.val() for checking the empty space which doesnt work for new created fields.and when i print value strored in "input.req.val()" it always picks up the value of first field all through the loop how can i apply validation in a way so that new fields are also validatd not only for empty but also for regular expressions
$(document).on('click', '#btnac', function() {
var empty = false;
$(':input.req').each(function() {
console.log($(':input.req').val());
var cbn = $('.newcbn').val();
var cba = $('.newcba').val();
var cban = $('.newcban').val();
var cbic = $('.newcbic').val();
var cuser = $('#cuser').val();
alert($(':input.req').val());
if ($(this).val() === '') {
empty = true;
} else if (/^[a-zA-Z ]+$/.test(cbn) === false) {
empty = true;
} else if (/^[a-zA-Z ]+$/.test(cba) === false) {
empty = true;
} else if (/^[0-9]+$/.test(cban) === false) {
empty = true;
} else if (/^[A-Za-z]{4}\d{7}$/.test(cbic) === false) {
empty = true;
} else if (/^[0-9]+$/.test(cuser) === false) {
empty = true;
} else {
empty = false;
}
});
if (empty) {
$('#btnac').attr('disabled', 'disabled');
} else {
$('#btnac').removeAttr('disabled');
}
});