Easy Form Validation with Javascript!

D

daniel.boorn

Form validation using JavaScript has never been as easy and simple! We
have developed a free generic form validation script that can validate
any form with very little JavaScript required in form!

For example:

A normal HTML form with out validation:

<form action="foobar.htm" method="get">
<div>Name: <input type="text" name="customerName" value=""></div>
<div>Email: <input type="text" name="customerEmail" value=""></div>
<div>Zip: <input type="text" name="customerZip" value=""></div>
<div><input type="submit" value="Submit"></div>
</form>

Simply add a few more attributes and you now have form validation:

<form action="foobar.htm" method="get">
<div>Name: <input type="text" required="yes" validate="text"
message="Please enter your name." name="customerName" value=""></div>
<div>Email: <input type="text" required="yes" validate="email"
message="Please enter a valid email address" name="customerEmail"
value=""></div>
<div>Zip: <input type="text" required="yes" validate="int"
message="Please enter a zip code" name="customerZip" value=""></div>
<div><input type="submit" value="Submit"
onClick="validate(this.form); return document.formSubmit;"></div>
</form>


You can get a free copy of the script here:
http://dboorn.com/javascript_form_validation.php?catID=69. Please feel
free to download and use for any of your needs. As always please feel
free to let me know your thoughts!
 
M

Matt Kruse

Form validation using JavaScript has never been as easy and simple!
As always please feel free to let me know your thoughts!

1. Not very backwards-compatible (not all browsers expose custom attributes
to js)
2. Very limited validation functionality
3. Creates potentially invalid HTML

Overall, it's not the best strategy.
 
V

VK

Simply add a few more attributes and you now have form validation:

<form action="foobar.htm" method="get">
<div>Name: <input type="text" required="yes" validate="text"

I would stay with the conventional styling way:
<input name="quantity" class="required numeric nozero"...
<input name="store" class="optional string"...
etc.

This way you would make it more cross-browser plus lesser risk to drive
crazy some over-sensitive parser :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top