To take things a step further you can even explore Ajax Form Validation which lets you supply real-time feedback using server-side scripts triggered by Java Script events.

The team at have made a video based on this article as a part of their Java Script training lessons which you can view below.

Here's an example of a custom validator that checks that an input is equal to some specified value: Attaches a validator to a form collection.

Only when all conditions have been satisfied do we reach the command, in which case the form will be submitted.

You'll see that the all validation scripts presented on this and subsequent pages adhere to the same basic format.

If, for example, you have a fixed navbar at the top of your page and you need to adjust the amount of padding between the top of the window and the focused field, you can override the following variable: Add custom validators to be run.

Validators should be functions that receive the j Query element as an argument and return an error message if the field is invalid.

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.If you need to support these browsers, you must add a polyfill like Ryan Seddon's H5F.Scroll to and focus the first field with an error upon validation of the form.If you find you need more restrictive validations for these fields, you can use the attribute to further constrain what's acceptable.Be careful that you aren't too restrictive though, which might lead to false negatives and a poor user experience.For example, you'd be surprised at what kinds of email addresses are considered valid according to standards.