1171Chapter 43 .Data-Entry Validation if (!minYear) { // (Web servers)

1171Chapter 43 .Data-Entry Validation if (!minYear) { // function called with specific day range parameters var dateStr = new String(monthDayFormat(mm) + / + monthDayFormat(dd) + / + yyyy) var testDate = new Date(dateStr) if (testDate.getTime() < (today.getTime() + (minDays * 24 * 60 * 60 * 1000))) { alert( The most likely range for this entry begins + minDays + days from today. ) } if (testDate.getTime() > today.getTime() + (maxDays * 24 * 60 * 60 * 1000)) { alert( The most likely range for this entry ends + maxDays + days from today. ) } You can also pass hard-wired, four-digit years as parameters. The following branch compares the entered year against the range specified by those passed year values. } else if (minYear && maxYear) { // function called with specific year range parameters if (yyyy < minYear || yyyy > maxYear) { // entered year is outside of range passed from calling function alert( The most likely range for this entry is between the years + minYear + and + maxYear + . If your source data indicates a date outside this range, then enter that date. ) } } else { For year parameters passed as positive or negative year differences, I begin processing by getting the four-digit year for today s date. Then I compare the entered year against the passed range values. If the entry is outside the desired range, an alert reveals the preferred year range within which the entry should fall. But the function does not return any value here because an out-of-range value is not critical for this application. // default year range (now set to (this year - 100) and (this year + 25)) var thisYear = today.getYear() if (thisYear < 100) { thisYear += 1900 } if (yyyy < minYear || yyyy > maxYear) { alert( It is unusual for a date entry to be before + minYear + or after + maxYear + . Please verify this entry. ) } } One more important validation is to make sure that the entered date is valid for the month and year. Therefore, the various date components are passed to functions to check against month lengths, including the special calculations for the varying length of February. Listing 43-15 shows these functions. The alert messages they display are smart enough to inform the user what the maximum date is for the entered month and year.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Leave a Reply