DEFAULT_DATE_RULE = {r:/^(/d{4})//(/d{2})//(/d{2})$/, y:1, m:2, d:3}; function checkDateValueA(val, checkList, begin, end, format, checkBlank) { if (val == null ||val == "" ) return !checkBlank; //judge format of value var dateVal = _parseDate(val, format); var dateBegin = null; var dateEnd = null; if(!dateVal) return false; if (checkList == null || checkList.length == 0) return true; var nVal = Date.parse(dateVal); var KW_BEGIN = "begin"; var KW_END = "end"; if( checkList.length == 2) { dateBegin = _parseDate(begin, format); dateEnd = _parseDate(end, format); if(!dateBegin || !dateEnd) return false; if ((nVal < Date.parse(dateBegin)) || (nVal > Date.parse(dateEnd))) return false; } else { if( checkList[0] == KW_BEGIN) { dateBegin = _parseDate(begin, format); if(!dateBegin) return false; if(nVal < Date.parse(dateBegin)) return false; } else if( checkList[0] == KW_END){ dateEnd = _parseDate(end, format); if(!dateEnd) return false; if(nVal > Date.parse(dateEnd)) return false; } } return true; } function checkDateFormatA(val, format, checkBlank) { if (val == ""||val == null) return !checkBlank; return (_parseDate(val, format) != null); } function _getDateRule(format){ if(!format || format == "") return DEFAULT_DATE_RULE; var retVal = {}; var rSet = { "YYYY" :["y","(//d{4})"], "YY" :["y","(//d{2})"], "MM" :["m","(//d{2})"], "DD" :["d","(//d{2})"] }; var rStr = ""; for(k in rSet){ rStr = (rStr == "")? k : rStr + "|" + k; } var m = format.match(new RegExp(rStr, "g")); if(!(m instanceof Array) || (m.length != 3)) return null; if(format.replace(new RegExp(rStr, "g"), "").match(//w/)) return null; for(i=0; i<m.length; i++){ retVal[rSet[m[i]][0]] = i+1; } if(!retVal.y || !retVal.m || !retVal.d) return null; rStr = format; for(k in rSet){ rStr = rStr.replace(new RegExp(k),rSet[k][1]); } retVal.r = new RegExp("^" + rStr + "$"); return retVal; } function _validateDate( y, m, d ) { var rule = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; if (d < 1) return false; if (m == 2) { if ((( y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) { if (d > 29) return false; } else { if (d > 28) return false; } } else if (!rule[m-1] || d > rule[m-1]) return false; return true; } function _convertYear(y){ var nY = y * 1; if(nY < 100){ return ( nY>69 ? "19" : "20") + y; } return y; } function _parseDate(val, format){ if(val == null) return null; var rule = _getDateRule(format); if(!rule) return null; var m = val.match(rule.r); if(!m) return null; var nY = _convertYear(m[rule.y]) * 1; var nM = m[rule.m] * 1; var nD = m[rule.d] * 1; if(_validateDate(nY, nM, nD)){ return (new Date(nY, nM-1, nD)); } return null; }