Importance of Form Validation
Form validation ensures a user not only enters or selects values when required but also enters appropriate and correctly formatted values. Feedback, contact and registration forms as well as content management systems that support insert, update and delete functions are all common scenarios where form validation should be implemented.
It’s important to ensure that data you store in a database is standardized, comprehensive and complete. Incorrectly formatted email addresses, invalid phone numbers or empty shipping addresses amongst other things will undermine the effectiveness and quality of the data in your web application.
You should also be wary of script errors that might be caused by a user entering incorrect variable types e.g. a user entering a string in a mortgage calculation box when an integer is required. Form validation also protects against a malicious user attempting to directly enter HTML, Javascript, SQL or other inappropriate code.
Validation in ASP was time consuming and cumbersome. The ASP.NET team in their wisdom tackled this area and developed the validation controls to make form validation a lot fastier and easier.
The Validation Controls
With ASP.NET 2.0 there are now 6 validation controls including the ValidationSummary control.
| Control Name | Purpose |
|---|---|
| RequiredFieldValidator | To ensure the user inputs a value |
| RegularExpressionValidator | To ensure that the value entered follows a specified pattern |
| RangeValidator | To ensure the input falls between 2 specified values |
| CompareValidator | To compare the value of one input control against the value of another input control or a fixed value |
| CustomValidator | Allows you to enter your own validation code |
| ValidationSummary | To display a summary report of all the validation errors in a page or within a validation group |
Read Part 2 How do Validation Controls work? |
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.
Get your best asp web hosting provider now and save 25%