I have this regex code below to validate a valid date.
function isValidDate(div) {
var reg = /^((0?\d)|(1[012]))\/([012]?\d|30|31)\/\d{1,4}$/;
var regs = /^\/\d{1,4}$/;
var dateField = $(div).val();
if (dateField == "") {
//alert('Invalid inclusive dates.');
return false;
} else {
if (reg.test(dateField) == false && regs.test(dateField) == false) {
// alert('Invalid inclusive dates.');
return false;
} else {
return true;
}
}
}
I am testing this code as you can see I have 2 condition in if (reg.test(dateField) == false && regs.test(dateField) == false) {
. In this line I am testing if the date is full date(1/1/2017) or (2017) only. If I input that two different dates it return false because of the condition. How to achieve this?.