You should NEVER rely on client-side validation of data entered in a web-based form. Since the validation takes place on the client’s side, it is really out of your control, and thus is not reliable (they could bypass/modify the requirements without your knowledge). On top of that – this library only works with Internet Explorer, so users with a different browser will not have their information validated at all!
Usage
Using this validation library is quite easy, it’s simply a matter of including some custom attributes on your form fields (which will be ignored if you stop using the
library or if it can’t be found).
Configuring The Library
There isn’t anything that you have to set up to use the library, however you can open “validate.js” and edit the following lines if you like;
[sourcecode language="javascript"]defaultValidationRule = “free”;
defaultErrorPrefix = “The following problem(s) occurred when processing your submission;
defaultErrorMessage = “The value in the ‘[ELEMENT]‘ field is invalid.”;[/sourcecode]
These determine the default operations of the library, as well as the prefix to the error message that will be displayed when something doesn’t validate correctly.
In defaultErrorMessage, you can insert [ELEMENT] whereever you want the name of the field that failed to validate to be displayed.
Importing the Library Into a Page
It is very easy to include the validation scripts in a page, the best way is to include code similar to this;
[sourcecode language="html"][/sourcecode]
Which will import the script file and run the functions as if they were in the current file.
This process can be automated in dynamic websites by either including that code in a header template for the site, or by creating a simple function such as that below, which works in PHP
[sourcecode language="javascript"] // Dumps in the code to “import” the javascript validation source file
function include_validation($path=”") {
echo “\n”;
}[/sourcecode]
The other option is to actually copy and paste the entire file into a page and put it between script tags. This is not recommended because it makes it harder to include on multiple pages and if you modify the rules then you need to update each and every file that includes the validation library.
Setting Up a Form for Validation
Before you can validate any field in a form, you need to add the following to the <form> tag that the fields reside in;
[sourcecode language="html"]onSubmit=”return validateForm(‘[name of the form]‘)”;[/sourcecode]
OR
[sourcecode language="html"]onSubmit=”return validateForm(this.name)”;[/sourcecode]
So you might end up with something like this;
[sourcecode language="html"]





















