I have this jquery code
<script type="text/javascript">
$(document).ready(function () {
var counter = 2;
$("#addButton").click(function () {
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'TextBoxDiv' + counter);
newTextBoxDiv.after().html('<input class="required" data-val="true" data-val-regex="Provide a valid date." data-val-regex-pattern="^\d{1,2}\/\d{1,2}\/\d{2}$" name="Date[' + counter + ']" id="Date[' + counter + ']" value="Date[' + counter + ']" style="width:165px" type="text" />' + ' ' +
'<input type="text" name="WorkHour' + counter +
'" id="WorkHour' + counter + '" value="" style="width:175px" >');
newTextBoxDiv.appendTo("#TextBoxesGroup");
$.validator.unobtrusive.parseDynamicContent('TextBoxesGroup input:last');
counter++;
});
$("#removeButton").click(function () {
if (counter == 2) {
alert("No more textbox to remove");
return false;
}
counter--;
$("#TextBoxDiv" + counter).remove();
});
$("#getButtonValue").click(function () {
var msg = '';
for (i = 1; i < counter; i++) {
msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val();
}
alert(msg);
});
});
</script>
Its generating a dynamic textbox also it's include removing.
I want to know if it is possible also to validate the dynamic textbox?