I have the following regex which validates dates:
//are not both dates
if (!methods._isDate(first[0].value) || !methods._isDate(second[0].value)) {
return options.allrules[rules[i]].alertText +
options.allrules[rules[i]].alertText2;
}
Regex below :
_isDate: function (value) {
var dateRegEx = new RegExp(/^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/);
return dateRegEx.test(value);
},
But this looks like for mmddyy, and my date is always ddmmyy.
Can you rewrite this regex? Please check it.
For DDMMYYYY, with optional leading
0for day and month, separators/or-, years1900–2099, without checking validity of29.,30.or31.day in month it would be:To use just 2-digit year format go with: