skip to content »

Validating html form

validating html form-39

Most error checking programs check each field one at a time, and display one error at a time.

validating html form-49validating html form-87validating html form-28

In the above form, we are calling validate() to validate data when onsubmit event is occurring.The server side form validations help keeping the form submission data consistent.The validations also help in lesser server side errors.Form security (preventing exploits like SQL injection, XSS attacks etc ) are to be handled in addition to form validation.Form validation is focussed towards the user input where as the security validations should be focused on how you use the data.The script has a catalog of almost all the common validation types built-in.

The idea is to create a set of “validation descriptors” associated with each element in a form.

It checks to see if the required fields are there, and if not, saves an error message into a variable for display: The difference with how the CGI writes the error message is that instead of a "\n", it uses the HTML paragraph tag to put a new line in between each error.

Form validation normally used to occur at the server, after the client had entered all the necessary data and then pressed the Submit button.

First, download the Java Script form validation script here.

The zip file contains the javascript file, examples.

For example, you can have an input field that should not be empty, should be less than 25 chars and should be alpha-numeric. In some dynamically programmed pages, it may be required to change the validations in the form at run time.