//Instant Validation with JavaScript-enabled WebDB //Listing 1 //The JavaScript function isDate checks whether the text entered in a field has //the date format MM/DD/YYYY, displaying an error message and returning a value //of “false” if it does not. isDate function isDate(theElement, theName) { // This function checks if the text entered in a field // has the format MM/DD/YYYY. // Only the format is checked, not the date itself. var date_regex = /^\d{1,2}\/\d{1,2}\/\d{4}$/; // ^ indicates start of expression // \d{1,2} - the \d means digits and {1,2} means 1 or 2 digits // $ indicates end f expression if (!date_regex.test(theElement.value)) { alert(theName + ": " + theElement.value + " is NOT a valid date"); theElement.focus(); return(false); } return(true); }