1168 Part V . Putting JavaScript to Work (Web site design and hosting)
1168 Part V . Putting JavaScript to Work Listing 43-13: Date Range Validations // Date Minus 90/Minus 20 function isM90_M20Date() { if (gField.value.length == 0) return true var thisYear = getTheYear() return isDate((thisYear - 90),(thisYear - 20)) } // Date Minus 70/Minus 0 function isM70_0Date() { if (gField.value.length == 0) return true var thisYear = getTheYear() return isDate((thisYear - 70),(thisYear)) } // Date Minus 5/Plus 10 function isM5_P10Date() { if (gField.value.length == 0) return true var thisYear = getTheYear() return isDate((thisYear - 5),(thisYear + 10)) } The naming convention I create for the functions includes the two range components relative to the current date. A letter M means the range boundary is minus a number of years from the current date; P means the range is plus a number of years. If the boundary should be the current year, a zero is used. Therefore, the isM5_P10Date() function performs range checking for boundaries between 5 years before and 10 years after the current year. Before performing any range checking, each function makes sure there is some value to validate. If the field entry is empty, the function returns true. This is fine here because dates are not required when the data is unknown. Next, the functions get the current four-digit year. The code here had to work originally with browsers that did not have the getFullYear()method available yet. Therefore, the Y2K fix described in Chapter 36 was built into the application: function getTheYear() { var thisYear = (new Date()).getYear() thisYear = (thisYear < 100)? thisYear + 1900: thisYear return thisYear } The final call from the range validations is to a common isDate() function, which handles not only the date range validation but also the validation for valid dates (for example, making sure that September has only 30 days). Listing 43-14 shows this monster-sized function. Because of the length of this function, I interlace commentary within the code listing.
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.