1169Chapter 43 .Data-Entry Validation Listing 43-14: Primary Date (Web hosting account)
1169Chapter 43 .Data-Entry Validation Listing 43-14: Primary Date Validation Function // date field validation (called by other validation functions that specify minYear/maxYear) function isDate(minYear,maxYear,minDays,maxDays) { var inputStr = gField.value To make it easier to work with dates supplied with delimiters, I first convert hyphen delimiters to slash delimiters. The pre-regular expression replaceString() function is the same one described in Chapter 34; it is located in the utility functions part of the validations.js file. // convert hyphen delimiters to slashes while (inputStr.indexOf( - ) != -1) { inputStr = replaceString(inputStr, - , / ) } For validating whether the gross format is OK, I check whether zero or two delimiters appear. If the value contains only one delimiter, then the overall formatting is not acceptable. The error alert shows models for acceptable date-entry formats. var delim1 = inputStr.indexOf( / ) var delim2 = inputStr.lastIndexOf( / ) if (delim1 != -1 && delim1 == delim2) { // there is only one delimiter in the string alert( The date entry is not in an acceptable format.nnYou can enter dates in the following formats: mmddyyyy, mm/dd/yyyy, or mm-dd-yyyy. (If the month or date data is not available, enter 01 in the appropriate location.) ) gField.focus() gField.select() return false } If there are two delimiters, I tear apart the string into components for month, day, and year. Because two-digit entries can begin with zeros, I make sure the parseInt() functions specify base-10 conversions. if (delim1 != -1) { // there are delimiters; extract component values var mm = parseInt(inputStr.substring(0,delim1),10) var dd = parseInt(inputStr.substring(delim1 + 1,delim2),10) var yyyy = parseInt(inputStr.substring(delim2 + 1, inputStr.length),10) For no delimiters, I tear apart the string and assume two-digit entries for the month and day and two or four digits for the year. } else { // there are no delimiters; extract component values var mm = parseInt(inputStr.substring(0,2),10) var dd = parseInt(inputStr.substring(2,4),10) var yyyy = parseInt(inputStr.substring(4,inputStr.length),10) }
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.