function textCounter( field, countfield, maxlimit ) { if ( field.value.length > maxlimit ) { field.value = field.value.substring( 0, maxlimit ); alert( 'Textarea value can only be ' + maxlimit + ' characters in length.' ); return false; } else { countfield.value = maxlimit - field.value.length; } } function isEmailAddr(email) { var result = false; var theStr = new String(email); var index = theStr.indexOf("@"); if (index > 0) { var pindex = theStr.indexOf(".",index); if ((pindex > index+1) && (theStr.length > pindex+1)) result = true; } return result; } function validRequired(formField,fieldLabel) { var result = true; if (formField.value == "") { alert('Please enter a value for the "' + fieldLabel +'" field.'); formField.focus(); result = false; } return result; } function allDigits(str) { return inValidCharSet(str,"0123456789"); } function inValidCharSet(str,charset) { var result = true; // Note: doesn't use regular expressions to avoid early Mac browser bugs for (var i=0;i 0) && (month < 13) && allDigits(elems[1]) && (day > 0) && (day < 32) && allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4)); } if (!result) { alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.'); formField.focus(); } } return result; } function validLocation(formField){ var str = formField.value if (str == ""){ alert('Please select your location from the location field.'); formField.focus(); return false; } else{ return true; } } function validateForm(theForm) { // Customize these calls for your form // Start -------> if (!validRequired(theForm.category,"Category")) return false; if (!validRequired(theForm.price,"Price")) return false; if (!validPrice(theForm.price,"Price",true)) return false; if (!validRequired(theForm.title,"Title")) return false; var textField = theForm.title if(textField.value.length > 80){ /* must be > 80, not == 80 or else the substring statement on the next line will cause the function to run again if the user dismisses the alert by pressing the 'enter' key rather than clicking 'OK'. */ textField.blur() /* move cursor out of form element to keep it from placing itself at position zero, causing an overwrite of the first character */ alert("Title field is too long. Maximum 80 character limit exceeded.") return false; } if (!validRequired(theForm.description,"Description")) return false; var textField = theForm.description if(textField.value.length > 2000){ /* must be > 1000, not == 2000 or else the substring statement on the next line will cause the function to run again if the user dismisses the alert by pressing the 'enter' key rather than clicking 'OK'. */ textField.blur() /* move cursor out of form element to keep it from placing itself at position zero, causing an overwrite of the first character */ alert("Description field is too long. Maximum 2000 character limit exceeded.") return false; } if (!validRequired(theForm.phone,"Contact Phone")) return false; //if (!validRequired(theForm.email,"Contact Email")) // return false; //if (!validEmail(theForm.email,"Contact Email",false)) // return false; if (!validRequired(theForm.status,"Status")) return false; if (!validRequired(theForm.password,"Password")) return false; //if (!validDate(theForm.available,"Date Available",true)) // return false; if ((theForm.password.value.substring(4,5) != 'i') && (!validLocation(theForm.location))) return false; return true; }