The validation of user input on a Web-based form is not a new, but a recurring, topic. Validation ensures that the user has entered correct data in an HTML form.
There are two types of validations: server side and client side. In the former case, user inputs are sent to the Web server, where they are validated by a server-side script written in ASP, ASP .NET, PHP, JSP, Servlets or Perl CGI. If the input is incorrect, the web server sends the form back to the user to re-enter the correct value.
In client-side validation, user inputs are validated within the Web browser by a client-side script such as JavaScript or VBScript. This method is preferred over server-side validation as it saves the roundtrip to the server when the validation fails.
With client-side validation you can ensure that correct data is sent to the server, at the very first place.
Using a validation library you can ensure that correct data goes into the database |
You can find numerous methods, tips and tricks and utilities (components and applets) on the Internet for carrying out form validations. You search for one and you will end up with many. Or, you could use the one that I have developed. It is a library of JavaScript validation functions, which I use in my Web-based projects. The library contains basic but frequently used validations for required fields, integer and decimal values, maximum characters in a textarea, select lists and date. On this month’s CD, you will find a file named validate.js (in the directory cdrom/src_code/validation) that contains the validation functions.
To begin with
All the pages in which you intend to use the validations must contain the following line between the
The HTML form that needs to be validated should have a name and must call a function–say, validate( )–when submitted. For example,