By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

Easy Form Validation with Javascript!

P: n/a
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_va...n.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!

Feb 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
da**********@gmail.com wrote:
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.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Feb 24 '06 #2

P: n/a
VK

da**********@gmail.com wrote:
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 :-)

Feb 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.