// Author: Stuart Cochrane // URL: www.freecontactform.com // Email: stuartc1@gmail.com // Date: 3rd July 2007 // Version: 3.0 Beta // License: Free to use and edit, but all comments must remain intact. // SPECIFY ALL REQUIRED FIELDS AND // VALIDATION TYPE // EXAMPLES: // one or more characters // required.add('[ FIELDID ]', 'NOT_EMPTY'); // alpha characters, no spaces // required.add('[ FIELDID ]', 'ALPHA'); // alpha characters, accept spaces // required.add('[ FIELDID ]', 'ALPHASPACE'); // numeric characters, no spaces // required.add('[ FIELDID ]', 'NUMERIC'); // numeric characters, also accepts +-. // required.add('[ FIELDID ]', 'NUMERICPLUS'); // alpha and numeric characters, no spaces // required.add('[ FIELDID ]', 'ALPHANUM'); // alpha and numeric characters, accept spaces // required.add('[ FIELDID ]', 'ALPHANUMSPACE'); // email address // required.add('[ FIELDID ]', 'EMAIL'); // date format yyyy-mm-dd, accepts - or / separators // required.add('[ FIELDID ]', 'YYYYMMDD'); // date format dd-mm-yyyy, accepts - or / separators // required.add('[ FIELDID ]', 'DDMMYYYY'); // date format mm-dd-yyyy, accepts - or / separators // required.add('[ FIELDID ]', 'MMDDYYYY'); // enter own regular expression, example: '^[0-9]{3}$' // required.add('[ FIELDID ]', '[ REGULAR EXPRESSION ]'); // NOTES: // [ FIELD ID ] = REPLACE WITH ACTUAL FIELD ID VALUE // example: = THIS // to specify your own regular expression, // enter the literal regex as type // example: required.add('fieldid', '^[0-9]{3}$'); // note: no leading or preceeding / (slash) is required! function $$(id) { try { var tmp = document.getElementById(id).value; } catch(e) { alert(id + " does not exist!\nvalidation is configured on a field with no ID"); return false; } if(tmp == "") { alert(id + " cannot be empty"); return false; } return tmp; } var required = { field : [], add : function(name, type) { this.field[this.field.length] = [name,type]; }, out : function() { return this.field; } } var validate = { check : function() { var tmp; // loop all required fields for(var i=0; i