Easy To Use Stock Form Validation Script

This versatile form validation script will work with any form that is configured to use it. See configuration instructions below the example.
* City and State

* Check a Radio Button
radio1 radio2 radio3 radio4 radio5

* Life Story

* Series of Fields
checkbox1 checkbox2

* Password

For a much more robust form validation script, see Form Validation on Steroids.

This script checks to see if any required form fields were left empty, unchecked, or unselected before submitting the form. To know which fields are required, the script employs a simple naming convention, where an asterisk (*) is used as the first character of the HTML name values for each required field like so:
<input type="text" name="*FieldName">
Since the script does not refer to any field by its name, you are allowed to have spaces in the name, and as you can see from the example, you can even group different field types together by giving them the same name.

I've also included a reset check, where the user will be asked for confirmation before the entire form is cleared.

So to use the script, give the fields you are requiring an asterisk as the first character in their HTML name values, and include the onsubmit and onreset statements as follows:
<form method="POST" action="YourCGIHere" onsubmit="return checkFields()" onreset="return Reset()">
NOTE: I used method="get" in my form since its action is an HTML document. You will probably need to change it to "post" if you are using a CGI script.

View the Source


View Source | Home | Contact