FORM Validation by Field

This page shows how to validate a form field using JavaScript. You should be familiar with HTML form. If not, see this tutorial: HTML Form Sample.

Here is a dummy field:

Type the last English alphabet here then press tab to move the focus away:

If you typed wrong, it will popup a alert box telling you so. View Source to see the code.

This validation is based on the onBlur event. It validates dynamically on a per field basis. It is quite simple. However, it doesn't prevent user from pressing the submit button with invalid values in the field. It only gives a warning that's all.

For validation that actually prevent the form being submitted, see: HTML FORM Validation

Reference: http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onblur.asp


Related Essays:


Page created: 2005-12.
© 2005 by Xah Lee.
Xah Signet