This current validation blocks 6/3/2015 1:15:20 AM. Basically, it looks for 2 Digits on dates and time, otherwise it fails. I need a jquery function that will replace IsDate function (below) and can validate 2 digit or single digits date and time , with or without AM/PM. Need help if I can fit in the jquery validation inside IsDate function, using the same structure. In otherwords it should pass
function isDate(dtStr, src) {
var daysInMonth = DaysArray(12)
var pos1 = dtStr.indexOf(dtCh)
var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
var strMonth = dtStr.substring(0, pos1)
var strDay = dtStr.substring(pos1 + 1, pos2)
var strYear = dtStr.substring(pos2 + 1, 10)
var tmCh = ":";
var Date = strMonth + dtCh + strDay + dtCh + strYear
var tm1 = dtStr.indexOf(tmCh)
var tm2 = dtStr.indexOf(tmCh, tm1 + 1)
var hrs = dtStr.substring(11, tm1)
var mins = dtStr.substring(tm1 + 1, tm2)
var secs = dtStr.substring(tm2 + 1)
var Time = hrs + tmCh + mins + tmCh + secs
strYr = strYear
if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
}
month = parseInt(strMonth)
day = parseInt(strDay)
year = parseInt(strYr)
if (pos1 == -1 || pos2 == -1) {
//alert("The date format should be : mm/dd/yyyy")
return false
}
if (strMonth.length < 1 || month < 1 || month > 12) {
//alert("Please enter a valid month")
return false
}
if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
//alert("Please enter a valid day")
return false
}
if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
return false
}
if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(Date, dtCh)) == false) {
//alert("Please enter a valid date")
return false
}
if (src) {
if (tm1 == -1 || tm2 == -1) {
//alert("The time format should be : hh:mm:ss")
return false
}
if (hrs.length != 2 || hrs < 0 || hrs > 24) {
//alert("Please enter a valid hour")
return false
}
if (mins.length != 2 || mins < 0 || mins > 60) {
//alert("Please enter valid minutes in an hour")
return false
}
if (secs.length != 2 || secs < 0 || secs > 60) {
//alert("Please enter valid seconds in an minute")
return false
}
if (dtStr.indexOf(tmCh, tm2 + 1) != -1 || isInteger(stripCharsInBag(Time, tmCh)) == false) {
//alert("Please enter a valid time")
return false
}
}
return true
}
function ValidateDate(src, args) {
var dt = args.Value;
var time;
var tbControl = document.getElementById(src.id.replace("Date", ""));
if ($(tbControl).data("includetime") === 'True') {
time = true;
} else {
time = false;
}
if (!isDate(dt, time)) {
args.IsValid = false;
} else {
args.IsValid = true;
}
return args.isValid;
}