» home
» contact
» terms of use

FREE SCRIPTS
» new
» text
» image
» utility
» background
» animation
» date/time

FREE ONLINE TOOLS
» code generators
» text animator
» drawing animator
» color animator
» slideshow factory
» javascript speed test

FREE BASIC SNIPLETS
» alert box
» image: multi-rollover
» pop-up: centering
» more

FREE'N'CRAZY
» realtime death counter
» eyeQ
» fun ticker

RECOMMENDED LINKS
» www.dynamicdrive.com
» www.hotscripts.com

Free Form Validation JavaScript
What's so special about this free form validation JavaScript? First of all it checks the fields while you are filling out the fields. The script masters three different tasks:

- It checks whether the required textfields are filled out.
- It validates the email address.
- It checks whether the textfield contains numbers only.

The free form validation script works fine with nternet Explorer 5x/6x/7x/8x/9x, Firefox 2x/3x, Opera 8x/9x/10x/11x, Google Chrome 3x/4x/5x/6x/7x/8x.


Demo Form
Use the demo form below and fill out the fields with incorrect and correct values in order to see how it works.
email address:

Validation: does the field contain a valid email address?

ZIP:

Validation: does the textfield contain numbers only?

city:

Validation: is the textfield filled out?

comment:

Validation: is the textarea-field filled out?

sex:
male female
Validation: has a radio button been selected?

age:

Validation: has an option been selected?



Configuration:

Step 1: Open your webpage and paste the following code anywhere between <body> and </body>. The code contains a sample-form that can be modified to your needs.



Step 2: Let's have a look at the sample form below, in order to set the mandatory form-fields.

<form name="anyname" action="submit.html" onsubmit="return check_final(this)" method="post">

email address:
<input type="text" name="email" class="isnotok" style="width:300px" onblur="return check_email(this,'email address:\nPlease enter a valid email address')">
Validation: does the field contain a valid email address?

ZIP:
<input type="text" name="ZIP" class="isnotok" style="width:300px" onblur="return check_numbers(this,'ZIP:\nOnly positive numbers and zero are allowed')">
Validation: does the textfield contain numbers only?

city:
<input type="text" name="city" class="isnotok" style="width:300px" onblur="return check_filledout(this,'city:\nPlease fill out the name of the city')">
Validation: is the textfield filled out?

comment:
<textarea name="comment" class="isnotok" rows="6" style="width:300px" onblur="return check_filledout(this,'comment:\nPlease enter your comment')"> </textarea>
Validation: is the textarea-field filled out?

sex:
<input type="radio" name="sex" value="Male" onclick="return check_filledout(this)">Male
<input type="radio" name="sex" value="Female" onclick="return check_filledout(this)">Female
Validation: has a radio button been selected?

age:
<select name="age" size="7" onclick="return check_filledout(this)">
<option>0 - 15
<option>15 - 21
<option>21 - 30
<option>31 - 40
<option>41 - 50
<option>51 - 60
<option>Above 60
</select>
Validation: has an option been selected?

<input type="submit" value="submit">

</form>


onsubmit="return check_final(this)"
The red element within <form>-tag calls the final validation check. It is absolutely mandatory! It should not be changed.

name="anyname"
Each field requires a unique name.

class="isnotok"
Each textfield and each textarea requires this class.
Do not change anything.
The class ist not required for type "radio" and "selection"

onblur="return check_email(this,'add your error message')
Use this if you want to apply an email validation check.
Can be used for field-type "text" or field "textarea".
Light green marks the text that appears when the email is not valid.

onblur="return check_filledout(this,'add your error message')"
Use this if you want to check whether the field is filled out.
Can be used for field-type "text" or field "textarea".
Light green marks the text that appears when the field is not filled out correctly.

onclick="return check_filledout(this)"
Use this for field-type "radio" and field-type "selection".
No comment reqeuired.

onblur="return check_numbers(this,'add your error message')"
Use this if you want to check whether the field consists of numbers only.
Can be used for field-type "text" or field "textarea".
Light green marks the text that appears when the field is not filled out correctly.



Step 3: Go between the <style>-tag </style>-tag and configure the style according to the instructions.

Step 4: Go on top of the <script>-code and enter the names of the form-fields (required fields only) according to the instructions.