var reFloat = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/ var reSignedInteger = /^(|-)?\d+$/ var reInteger = /^\d+$/ var reAlpha = /^[a-zA-Z!@]+$/ var reAlphanumeric = /^[ a-zA-Z0-9!@]+$/ var reEmail = /^.+\@.+\..+$/ var reWhitespace = /^\s+$/; function isEmpty(s) { return ((s == null) || (s.length == 0)); } function isWhitespace (s) { // Is s empty? return (isEmpty(s) || reWhitespace.test(s)); } function warnInvalid (theField, s) { theField.focus(); theField.select(); alert(s); return false; } function Validate(theField, emptyOK, errorMsg, reEditRules) { // Expect the following parameters // 1st parameter : a form field // 2nd parameter : true or false --> emptyOK or emptyNotOK // 3rd parameter : error message // 4th parameter : type of edit rule --> regexp, no enclosed strings var rc = true; if (theField != null) { if (isWhitespace(theField.value)) { if (emptyOK == false) { //validation rule -- data expected alert(errorMsg + ": no value entered"); theField.focus(); return false; } else return true; } if (reEditRules != null) { rc = eval( reEditRules + ".test('" + theField.value + "')" ); if (rc == false) { warnInvalid (theField, errorMsg); return false; } } } return true; } function checkForm(f) { ret=true; if (!Validate(f.surname, false, 'You must enter a valid surname', reAlphanumeric)) return false; if (!Validate(f.firstname, false, 'You must enter a valid firstname', reAlphanumeric)) return false; // if (!Validate(f.country, false, 'You must choose a country', reAlphanumeric)) // return false; if (!Validate(f.email, false, 'You must enter a valid email address', reEmail)) return false; return ret; }