skip to content »

Validating javascript text fields

validating javascript text fields-22

Server-side validation is more secure but often more tricky to code, whereas client-side (Java Script) validation is easier to do and quicker too (the browser doesn't have to connect to the server to validate the form, so the user finds out instantly if they've missed out that required field! In this tutorial we'll build a simple form with client-side Java Script validation.You can then adapt this form to your own requirements.

Form validation helps us achieve these goals — this article tells you what you need to know.If the data entered by a client was incorrect or was simply missing, the server would have to send all the data back to the client and request that the form be resubmitted with correct information.This was really a lengthy process which used to put a lot of burden on the server.Let's build a simple form with a validation script.I will admit that I am not a huge fan of client-side scripting (for the exception of HTML, of course) because of its relatively low power and compatibility between browsers.Simply replace the position of forms[x] with the form name.

For example, if a form’s name was ‘feedback’, calling that specific form within the document would be written like this: Each form element belongs, or lives, within one single form, so when error checking multiple forms on one single page, no discrepancies will surface.

form validation can be implemented in a number of different ways.

The truth is that none of us filling in forms — there is a lot of evidence to show that users get annoyed by forms, and are one of main things that will cause them to leave and go somewhere else if they are done badly. We want to make filling out web forms as non-horrible as possible, so why do we insist on blocking our users at every turn?

At the end, there's a little exercise to keep you busy too!

Form validation is the process of checking that a form has been filled in correctly before it is processed.

The following code shows the implementation of this validate() function.