//Instant Validation with JavaScript-enabled WebDB //Listing 4 //The JavaScript function isEmail checks whether the text entered in a field has a format //appropriate for an e-mail address (xxxx@yyyy.zzzz or wwww.xxxx@yyyy.zzzz), displaying an //error message and returning a value of “false” if it does not. function isEmail(theElement, theName) { // This function checks if the text entered in a field has the // format xxxx@yyyy.zzzz. var email_regex = /^\w+\.{0,1}\w+@\w+\.\w+$/; if (!email_regex.test(theElement.value)) { alert(theName + ": "+ theElement.value + " is not a valid e-mail address"); theElement.focus(); return(false); } return(true); }