Adding Validation

Validating user input is a common requirement of any application that relies on the user to provide data. The ASP.NET framework provides tools to make input validation easy. ASP.NET supports validation by providing server controls that handle the validation process. Each server control placed on a form is responsible for validating the value in some other control on the form. The validation process occurs both on the client (if the browser is capable) and on the server, or just on the server (if the browser can’t handle it). Validation occurs on the server, even if it occurs on the client, to prohibit a hostile client from submitting invalid data.

The server controls that relate to validation are:

CompareValidator

Compares the value in a control with either a constant value or the value in another control. The developer chooses the comparison to be performed (equal, less than, greater than, etc.). The validation succeeds if the comparison is True.

CustomValidator

Allows the application to perform validation logic that isn’t provided by the standard comparison controls.

RangeValidator

Compares the value in a control to a given range. The validation succeeds if the value is within the range.

RegularExpressionValidator

Compares the value in a control to a given regular expression. The validation succeeds if the value is matched by the regular expression.

RequiredFieldValidator

Checks that a value has been entered into a control. The validation succeeds if the value ...

Get Programming Visual Basic .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.