Current Version: 1.0.5 relesead on 02/02/2007
The validations has been made easy!
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
If you want, you can add a link to www.web-ma.com,
making it easy for others to recognize the author of this script.
Why my own validator?The idea to develop this validator suite comes using the ASP.Net framework.
Unfortunately after some days of use, I've completely refused the idea to continue to waste time after the WebForm and the logic behind that.
So, accordingly to previous experience mutued by years of experience in old ASP language, I've decided to take the best of the ASP.Net framework idea and merge with it.
The result is my own validator.
Certainly it has its own limit, that unfortunately is imposed by the user's browser configuration.
This require some extra work for the programmer to create some server side validation rules.
But if you think well (and in particularly if you have a bit of experience in ASP.Net programming) its the same thing that occur on the framework when you hit the submit button. In that case is the server that just re-parsing the coded logic, using its interal architecture perform the validation also (or only, if a downlevel browser is detected) in a server side way.
So this could seem expensive to implement, but actually I prefer this to the many hours lost after Page_OnInit or Page_Load event and Request.Form collection returned empty.
To believe, just take a look to the example below.
This mean create a lot of code, functions etc spreaded along HTML pages or create specialized .js files that let you validate single forms along your web site.
The idea is to create a set of validator associated with each element in a form. The validation is nothing that a specialized function that perform the type of validation requested.
Each field in the form can have 0, 1, or more validations. For example, the input should not be empty, should be less than 25 chars, should be alpha-numeric, etc
You can associate a set of validator for each input field in the form and forget of all, worrying just to catch the submit result.
For each single validator, you will able to set, a part the basic parameters, the error message, the location where it will be displayed, the CSS style and if the field should get the focus after a wrong validation.
Using The Script1. Include validator.js in your html file just before closing the HEAD tag
2. Just after defining your form, create a form validator object passing the name of the form:
3. Now add the validations required
A) The first parameter is the name of the field;
B) The second parameter is the validation function to be call during the validation process.
C) The third parameter is an extra param is used to pass an extra param value to the validator function.
D) The fourth param is the message.
E) The fifth param is the location where the message will be displayed. Choose from right, left or alert.
F) The sixth param is the CSS style that will be applyied to the validator message.
For instance a CSS property like font-size will became fontSize, and so on.
4. You can add any number of validations where validation is required.
5. Don't forget to add the ID property to the HTML element to be validated.
That's it! You are ready to go.
ExampleThe example below will make the idea clearer
Adding an Extra Validator FunctionIf you want to add an extra custom validation function just before the final submit, you can simply create your own function with your own name, but without parameters. Then using the ExtraValidatorFunction of your form validator object, pass the name of the function that will take the extra validation, and that's all.
The extra function can obviously contain all code that you need, including extra function call to extra function that contains parameters.
The important thing is to remember that function should just return true or false as well as the other validation functions do.
To associate the validation function with the validator object, use this command:
Clear All ValidationsIn some dynamically programmed pages, it may be required to change the validations in the form at run time. For such cases, a function is included which clears all validations in the validator object.
This function clears all validations you set.
You will not need this method in most cases.
Table of Validator FunctionsA small set of valitor functions has been released with this first version of the code. You are free to add your own set as well as extend the provided one.
The validator provided are:
Back to Open Source Utility list.
Copyright © 2006 - 2008 http://www.web-ma.com. All rights reserved.