View Full Version : General form validation script

05-04-2004, 03:55 AM
I've been looking around for script that is flexible enough for various diffrent form and field names. The only thing i really want to check is if there is a value typed in or not. The thing is that i want it to error out an alert box with the form field value name that is blank. Ex: "Please fill out the NAME field".

This error would be typical for all other fields "Please fill out the ZIPCODE" field". Does any one have a flexible enough script for this or any ideas?

05-04-2004, 04:12 AM
how does this work for you? it checks to make sure the email address has a @ and a . in it, too

function validate() {
if ((document.feedback.email.value=="")||
alert ("You must fill in all required fields!")
return false
function emailcheck() {
var e=document.feedback.email.value
if ((e.indexOf("@")==-1)||
alert("Please input a valid email address!")
<H1>Feed Back Form</H1>
<FORM enctype="text/plain" name="feedback" method="post" action="mail_form.cgi" onsubmit="return validate()">
<SELECT name="subject">
<OPTION value="choose" selected>--Choose A Subject--</OPTION>
<OPTION value="question">Ask A Question</OPTION>
<OPTION value="comment">Give A Comment</OPTION>
<OPTION value="change">Suggest A Change</OPTION>
<OPTION value="other">Other</OPTION>
<INPUT size="26" name="email" onblur="emailcheck()">
<TEXTAREA name="body" rows="4" cols="55"></TEXTAREA>
<INPUT type="submit" value="Send">
<INPUT type="button" value="Reset">

05-04-2004, 04:32 AM
Check out beetle's fValidate (http://www.peterbailey.net/fValidate/). It is a comprehensive form validation tool that covers all types of fields.