1/* This is a date validator */ 2 3function checkdate(objName) 4{ 5 var datefield = objName; 6 if (isDate(objName.value) == false) 7 { 8 datefield.value = ""; 9 alert("That date is invalid. Please try again."); 10 datefield.focus(); 11 return false; 12 } 13 else 14 { 15 return true; 16 } 17} 18 19function isDate(DateToCheck) 20{ 21 if(DateToCheck=="") 22 { 23 return true; 24 } 25 var m_strDate = FormatDate(DateToCheck); 26 if(m_strDate=="") 27 { 28 return false; 29 } 30 31 var m_arrDate = m_strDate.split("/"); 32 var m_DAY = m_arrDate[0]; 33 var m_MONTH = m_arrDate[1]; 34 var m_YEAR = m_arrDate[2]; 35 36 if(m_YEAR.length > 4) 37 { 38 return false; 39 } 40 41 m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR; 42 var testDate=new Date(m_strDate); 43 if (testDate.getMonth()+1==m_MONTH) 44 { 45 return true; 46 } 47 else 48 { 49 return false; 50 } 51} 52 53function FormatDate(DateToFormat,FormatAs){ 54if(DateToFormat==""){return"";} 55if(!FormatAs){FormatAs="dd/mm/yyyy";} 56 57var strReturnDate; 58FormatAs = FormatAs.toLowerCase(); 59DateToFormat = DateToFormat.toLowerCase(); 60var arrDate 61var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December"); 62var strMONTH; 63var Separator; 64 65while(DateToFormat.indexOf("st")>-1){ 66DateToFormat = DateToFormat.replace("st",""); 67} 68 69while(DateToFormat.indexOf("nd")>-1){ 70DateToFormat = DateToFormat.replace("nd",""); 71} 72 73while(DateToFormat.indexOf("rd")>-1){ 74DateToFormat = DateToFormat.replace("rd",""); 75} 76 77while(DateToFormat.indexOf("th")>-1){ 78DateToFormat = DateToFormat.replace("th",""); 79} 80 81if(DateToFormat.indexOf(".")>-1){ 82Separator = "."; 83} 84 85if(DateToFormat.indexOf("-")>-1){ 86Separator = "-"; 87} 88 89 90if(DateToFormat.indexOf("/")>-1){ 91Separator = "/"; 92} 93 94if(DateToFormat.indexOf(" ")>-1){ 95Separator = " "; 96} 97 98arrDate = DateToFormat.split(Separator); 99DateToFormat = ""; 100 for(var iSD = 0;iSD < arrDate.length;iSD++){ 101 if(arrDate[iSD]!=""){ 102 DateToFormat += arrDate[iSD] + Separator; 103 } 104 } 105DateToFormat = DateToFormat.substring(0,DateToFormat.length-1); 106arrDate = DateToFormat.split(Separator); 107 108if(arrDate.length < 3){ 109return ""; 110} 111 112var DAY = arrDate[0]; 113var MONTH = arrDate[1]; 114var YEAR = arrDate[2]; 115 116 117 118 119if(parseFloat(arrDate[1]) > 12){ 120DAY = arrDate[1]; 121MONTH = arrDate[0]; 122} 123 124if(parseFloat(DAY) && DAY.toString().length==4){ 125YEAR = arrDate[0]; 126DAY = arrDate[2]; 127MONTH = arrDate[1]; 128} 129 130 131for(var iSD = 0;iSD < arrMonths.length;iSD++){ 132var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase(); 133var MonthPosition = DateToFormat.indexOf(ShortMonth); 134 if(MonthPosition > -1){ 135 MONTH = iSD + 1; 136 if(MonthPosition == 0){ 137 DAY = arrDate[1]; 138 YEAR = arrDate[2]; 139 } 140 break; 141 } 142} 143 144var strTemp = YEAR.toString(); 145if(strTemp.length==2){ 146 147 if(parseFloat(YEAR)>40){ 148 YEAR = "19" + YEAR; 149 } 150 else{ 151 YEAR = "20" + YEAR; 152 } 153 154} 155 156 157 if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){ 158 MONTH = "0" + MONTH; 159 } 160 if(parseInt(DAY)< 10 && DAY.toString().length < 2){ 161 DAY = "0" + DAY; 162 } 163 switch (FormatAs){ 164 case "dd/mm/yyyy": 165 return DAY + "/" + MONTH + "/" + YEAR; 166 case "mm/dd/yyyy": 167 return MONTH + "/" + DAY + "/" + YEAR; 168 case "dd/mmm/yyyy": 169 return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR; 170 case "mmm/dd/yyyy": 171 return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR; 172 case "dd/mmmm/yyyy": 173 return DAY + " " + arrMonths[MONTH -1] + " " + YEAR; 174 case "mmmm/dd/yyyy": 175 return arrMonths[MONTH -1] + " " + DAY + " " + YEAR; 176 } 177 178return DAY + "/" + strMONTH + "/" + YEAR;; 179 180} //End Function 181 182 183 184 185 186function checkTime(objName) 187{ 188 189 var timefield = objName; 190 var timeValue = objName.value; 191 192 var noSpace = ""; 193 var regexTime = /^(10|11|12|[1-9]):[0-5][0-9] pm|am$/ 194 195 if (timeValue.length > 0) { 196 197 timeValue = timeValue.toLowerCase().replace(/\./g, ''); //remove any periods 198 timeValue = timeValue.replace('p', ' p'); //put a space before pm 199 timeValue = timeValue.replace('a', ' a'); //put a space before am 200 timeValue = timeValue.replace(/ {1,}/g, ' ');
200 //make all spaces single spaces 201 202 //if no colon assume top of the hour and add :00 203 if (timeValue.indexOf(':') < 0) { 204 205 var timeSplitArr = timeValue.split(' '); 206 timeSplitArr[0] = timeSplitArr[0] + ':00'; 207 208 if (timeValue.indexOf(' ') > 0) { 209 timeValue = timeSplitArr[0] + ' ' + timeSplitArr[1] 210 } else { 211 timeValue = timeSplitArr[0] 212 } 213 } 214 215 //replace current time with fixed time before check 216 timefield.value = timeValue; 217 218 if (!regexTime.test(timeValue)) { 219 alert("That time is invalid. Please try again (hh:mm am/pm)."); 220 return false; 221 } 222 223 } 224 225 226 if (IsValidTime(timeValue) == false) 227 { 228 alert("That time is invalid. Please try again (hh:mm:ss am/pm)."); 229 return false; 230 } 231 else 232 { 233 return true; 234 } 235} 236 237function chkdate(objName) { 238 239 var strDatestyle = "US"; //United States date style 240 //var strDatestyle = "EU"; //European date style 241 var strDate; 242 var strDateArray; 243 var strDay; 244 var strMonth; 245 var strYear; 246 var intday; 247 var intMonth; 248 var intYear; 249 var booFound = false; 250 var datefield = objName; 251 var strSeparatorArray = new Array("-"," ","/","."); 252 var intElementNr; 253 var err = 0; 254 255 var vDate = new Date(); 256 257 var strMonthArray = new Array(12); 258 strMonthArray[0] = "Jan"; 259 strMonthArray[1] = "Feb"; 260 strMonthArray[2] = "Mar"; 261 strMonthArray[3] = "Apr"; 262 strMonthArray[4] = "May"; 263 strMonthArray[5] = "Jun"; 264 strMonthArray[6] = "Jul"; 265 strMonthArray[7] = "Aug"; 266 strMonthArray[8] = "Sep"; 267 strMonthArray[9] = "Oct"; 268 strMonthArray[10] = "Nov"; 269 strMonthArray[11] = "Dec"; 270 271 strDate = datefield.value; 272 if (strDate.length < 1) 273 { 274 return true; 275 } 276 277 for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 278 { 279 if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 280 { 281 strDateArray = strDate.split(strSeparatorArray[intElementNr]); 282 if (strDateArray.length != 3) 283 { 284 err = 1; 285 return false; 286 } 287 else 288 { 289 strDay = strDateArray[0]; 290 strMonth = strDateArray[1]; 291 strYear = strDateArray[2]; 292 } 293 booFound = true; 294 } 295 } 296 if (booFound == false) 297 { 298 if (strDate.length>5) 299 { 300 strDay = strDate.substr(0, 2); 301 strMonth = strDate.substr(2, 2); 302 strYear = strDate.substr(4); 303 } 304 } 305 if (strYear.length == 2) 306 { 307 intYear = parseInt(strYear, 10); 308 if (isNaN(intYear)) 309 { 310 //strYear = vDate.getFullYear(); 311 } 312 else 313 { 314 if (intYear > 30) 315 { strYear = '19' + strYear; } 316 else 317 { strYear = '20' + strYear; } 318 } 319 } 320 321 // US style 322 if (strDatestyle == "US") 323 { 324 strTemp = strDay; 325 strDay = strMonth; 326 strMonth = strTemp; 327 } 328 329 intday = parseInt(strDay, 10); 330 if (isNaN(intday)) 331 { 332 err = 2; 333 return false; 334 } 335 336 intMonth = parseInt(strMonth, 10); 337 if (isNaN(intMonth)) 338 { 339 for (i = 0;i<12;i++) 340 { 341 if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 342 { 343 intMonth = i+1; 344 strMonth = strMonthArray[i]; 345 i = 12; 346 } 347 } 348 if (isNaN(intMonth)) 349 { 350 err = 3; 351 return false; 352 } 353 } 354 intYear = parseInt(strYear, 10); 355 if (isNaN(intYear)) 356 { 357 err = 4; 358 return false; 359 } 360 if (intYear < 1500) 361 { 362 err = 11; 363 return false; 364 } 365 366 if (intMonth>12 || intMonth<1) 367 { 368 err = 5; 369 return false; 370 } 371 if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) 372 { 373 err = 6; 374 return false; 375 } 376 if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 377 { 378 err = 7; 379 return false; 380 } 381 if (intMonth == 2) 382 { 383 if (intday < 1) 384 { 385 err = 8; 386 return false; 387 } 388 if (LeapYear(intYear) == true) 389 { 390 if (intday > 29) 391 { 392 err = 9; 393 return false; 394 } 395 } 396 else 397 { 398 if (intday > 28) 399 { 400 err = 10; 401 return false; 402 } 403 } 404 } 405 if (strDatestyle == "US") 406 { 407 // datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear; 408 datefield.value = intMonth + "/" + intday+"/" + strYear; 409 } 410 else 411 { 412 datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear; 413 } 414 return true; 415} 416 417function LeapYear(intYear) 418{ 419 if (intYear % 100 == 0) 420 { 421 if (intYear % 400 == 0) { return true; } 422 } 423 else 424 { 425 if ((intYear % 4) == 0) { return true; } 426 } 427 return false; 428} 429 430function doDateCheck(from, to) 431{ 432 if (Date.parse(from.value) <= Date.parse(to.value)) 433 { 434 alert("The dates are valid."); 435 } 436 else 437 { 438 if (from.value == "" || to.value == "") 439 alert("Both dates must be entered."); 440 else 441 alert("To date must occur after the from date."); 442 } 443} 444function doCompareDates(from,to) 445{ 446 if (Date.parse(from) < Date.parse(to)) 447 { return true; } 448 else 449 { return false; } 450} 451 452function doCompareDatesEqual(from,to) 453{ 454 if (Date.parse(from) <= Date.parse(to)) 455 { return true; } 456 else 457 { return false; } 458} 459 460function IsValidTime(timeStr) 461{
462 // Checks if time is in HH:MM:SS AM/PM format. 463 // The seconds and AM/PM are optional. 464 465 var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/; 466 467 if (timeStr.length < 1) 468 { 469 return true; 470 } 471 472 var timeVal = timeStr.toLowerCase(); 473 var tmpChar = timeVal.charAt(timeVal.length-1); 474 475 if (tmpChar == "a" || tmpChar == "p") 476 { 477 if (tmpChar.indexOf("m")<0) 478 { 479 timeVal = timeVal + "m" 480 } 481 } 482 483 var matchArray = timeVal.match(timePat); 484 485 486 if (matchArray == null) 487 { 488 // alert("Time is not in a valid format."); 489 return false; 490 } 491 492 hour = matchArray[1]; 493 minute = matchArray[2]; 494 second = matchArray[4]; 495 ampm = matchArray[6]; 496 497 if (second=="") { second = null; } 498 if (ampm=="") { ampm = null } 499 500 if (hour < 0 || hour > 23) 501 { 502 // alert("Hour must be between 1 and 12. (or 0 and 23 for military time)"); 503 return false; 504 } 505 506 if (hour <= 12 && ampm == null) 507 { 508 ampm = "am" 509 } 510 511 if (hour > 12 && ampm != null) 512 { 513 // alert("You can't specify AM or PM for military time."); 514 return false; 515 } 516 517 if (minute<0 || minute > 59) 518 { 519 // alert ("Minute must be between 0 and 59."); 520 return false; 521 } 522 523 if (second != null && (second < 0 || second > 59)) 524 { 525 // alert ("Second must be between 0 and 59."); 526 return false; 527 } 528 529 return true; 530 531} 532 533
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.