Visual Basic (3539)
Validating user input in a form
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:How can I validate a form's user input?
Answer:You can either put an onblur event handler on each input field (text input, radio buttons, check boxes, select lists) which will get triggered each time a user leaves any field. This is useful if there are many input fields on the screen that can be evaluated independently.
If you either have only a few fields or if some of the fields' rules depend on other fields, then you might prefer to validate upon submission of the form.
Use the form's onsubmit event for that as the following example shows.
If the validation fails (user puts in an age under 18) then the data does not get posted and the form stays.