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