Snippet:
var msie = window.document.documentMode;
/****
* Checks a controls value to see if it is a Date Value or not
*
* Parameters:
* @cntrl - String; the Control ID value
* @success - Function(); The Success function to execute
* @fail - Function(); The Fail function to execute
*/
function ValidDate(cntrl, success, fail) {
var valid = false;
if (msie !== undefined) {
var dtString = cntrlIDs[cntrl].value;
var date = new Date(dtString);
if (!isNaN(date)) {
dtString = dtString.replace(/-/g, "/");
// Assumed pattern: MM/dd/CCYY
var parts = dtString.split("/")
var dd = parseInt(parts[1], 10); // Day Number
var mm = parseInt(parts[0], 10); // Month Number
var yr = parseInt(parts[2], 10); // Year Number
if (dd === date.getDate()
&& mm === (date.getMonth() + 1) // Zero-based Calendar months
&& yr === date.getFullYear()) {
//Only execute Success function, if AND ONLY if all date parts are equal
valid = true;
}
}
} else {
if (Date.parse(cntrlIDs[cntrl].value)) {
valid = true;
}
}
if (valid) {
cntrlIDs[cntrl].classList.remove('invalid');
if ($.isFunction(success)) {
success();
}
} else {
cntrlIDs[cntrl].classList.add('invalid');
if ($.isFunction(fail)) {
fail();
}
}
}
Comments
Post a Comment