Typically, when we're collecting user input, it is important that the user input conform to some set of guidelines. Perhaps certain input is required or must be numeric. Maybe the input needs to be less than a certain value or between two constant values. Or perhaps the input needs to conform to some pattern, such as a United States ZIP code, which needs to be in the form XXXXX or XXXXX-XXXX, where each X is a digit. The process of ensuring that a user's input is in the correct format is referred to as input validation. In previous technologies, such as ASP and PHP, input validation was a real bear, requiring developers to write code to validate user input. With ASP.NET, however, input validation is a breeze because of its various validation Web controls. In this hour we examined four such controls: the RequiredFieldValidator, the CompareValidator, the RangeValidator, and the RegularExpressionValidator. This hour concludes our examination of collecting user input. Starting with the next hour we'll be turning our attention to working with databases. Although there are no more hours dedicated to collecting user input, a number of the examples throughout the remainder of the book will require user input, so be certain that you have a firm grasp on this material before continuing. |