Below code is an existing code in my working project and I didn't start it. All I know is that this code is validating a Date
if it is valid or invalid format.
function isValidDate(div, field) {
var reg = /^((0?\d)|(1[012]))\/([012]?\d|30|31)\/\d{1,4}$/;
var dateField = $("#" + div + " #" + field + "").val();
if ((dateField == "") || (dateField == "1/1/0001") || (dateField == "MM/dd/yyyy"))
{
alert('Invalid Date.');
return false;
} else {
if (reg.test(dateField) == false) {
alert('Invalid Date.');
return false;
} else {
return true;
}
}
}
My question is please tell me what is what does really the purpose of this line var reg = /^((0?\d)|(1[012]))\/([012]?\d|30|31)\/\d{1,4}$/;
What this code really do and if possible can explain it step by step because I am really noob in regex I can't even read it. Thanks.