Validating a form with javascript

When form input is important, it should always be verified using a secure server-side script.

Otherwise a browser with Java Script disabled, or a hacker trying to compromise your site, can easily submit invalid data. The first test in the example is therefore only necessary in order to provide a different error message when the input is blank.

The zip file contains the javascript file, examples.

The script has a catalog of almost all the common validation types built-in.

Other form values are available using a similar syntax, although this becomes more complicated if you're using SELECT lists, checkboxes or radio buttons (see below for examples). All you need to do is extend the command is encountered, execution of the function is halted.

In other words if the first condition fails, the second condition will not be tested and so forth.

Form validation is the process of making sure that data supplied by the user using a form, meets the criteria set for collecting data from the user.If so, it allows it to be submitted to the server and (usually) saved in a database; if not, it gives you error messages to explain what you've done wrong (provided you've done it right).form validation can be implemented in a number of different ways.The idea is to create a set of “validation descriptors” associated with each element in a form.The “validation descriptor” is nothing but a string specifying the type of validation to be performed.

Leave a Reply