Are there any free frameworks or apis or pre-built javascript files that I can easily plug in for form validation?
Printable View
Are there any free frameworks or apis or pre-built javascript files that I can easily plug in for form validation?
There is one here:
http://www.javascript-coder.com/html...lidation.phtml
Which is easy to use. The problem is this is not W3C compliant, so your page won't validate. I am currently working on something similar which is W3C compliant.
You could just write your own, it won't be as heavy as a 'prepared' one.
I am almost finished with an object oriented javascript form validation, similar to the one above.
The size of the script include is less than the average jpeg image.
If you just want a quick script to check required fields then something like this will do:
And the HTML form:Code:function validate()
{
var output = true;
var msg = "Please correct the following errors:\n";
if(document.forms["contact_us"].name.value.length < 3) { output = false; msg += "\n - Name is missing or too short."; }
if(document.forms["contact_us"].email.value.length < 5) { output = false; msg += "\n - Email address is missing or too short."; }
if(!output)
{
alert(msg);
return false;
}
else
{
return true;
}
}
Note the onsubmit event in the <form> tag. This tells the form to call the validate function when submitted, the validate function returns true/false. If false the form will not be submitted, and a message will popup with the errors.Code:<form action='somewhere.html' name='contact_us' method='post' onsubmit='return validate()'>
Name: <input type='text' name='name' />
Email: <input type='text' name='email' />
<input type='submit' name='form_submit' />
</form>
Just added this to the Codebank: Easy form validation - http://www.vbforums.com/showthread.php?p=3380227