Validation Controls in
Validation Controls in
Today
What Validation controls do Benefits & Limitations Six Validation Controls Implementation Example
Each control:
Validates user inputs on client-side using JavaScript
When possible
Bomb-proof
Server-side validation
Limitations
Must remember to check on server
Page.IsValid statement
RegularExpressionValidator
Check format against a specific pattern E-mail address, phone number, zip code, etc.
5.
CustomValidator
Write own code Server- or client-side
6.
ValidationSummary
Summarizes all errors on page
Implementation
Often need > 1 validator per input
Only RequiredFieldValidator checks for empty fields
Page.IsValid
Check in event handler
if (!Page.IsValid) return;
Validation Groups
Allow validation controls to be assigned to groups Page can have several groups Act independently Only group associated with postback event must have valid entries Example: No groups, groups
Example:
Required, Compare, Range, & Custom (client- and server-side script) Validation.aspx (source)
Summary
Easy to use Flexible
Validate any type of input
Combines client- and server-side validation in one control Bomb-proof server-side validation