Types of Validation Controls in ASP NET There

  • Slides: 8
Download presentation
Types of Validation Controls in ASP. NET

Types of Validation Controls in ASP. NET

There are six types of validation controls in ASP. NET 1. 2. 3. 4.

There are six types of validation controls in ASP. NET 1. 2. 3. 4. 5. 6. Required. Field. Validation Control Compare. Validator Control Range. Validator Control Regular. Expression. Validator Control Custom. Validator Control Validation. Summary

Required. Field. Validation Control • The Required. Field. Validator control is simple validation control,

Required. Field. Validation Control • The Required. Field. Validator control is simple validation control, which checks to see if the data is entered for the input control. We can have a Required. Field. Validator control for each form element on which we wish to enforce Mandatory Field rule. Example: <asp: Required. Field. Validator ID="Required. Field. Validator 3" runat="server”Style="top: 98 px; left: 367 px; position: absolute; height: 26 px; width: 162 px“ Error. Message="password required" Control. To. Validate="Te xt. Box 2"> </asp: Required. Field. Validator>

Compare. Validator Control • The Compare. Validator control allows us to make comparison to

Compare. Validator Control • The Compare. Validator control allows us to make comparison to compare data entered in an input control with a constant value or a value in a different control. • It can most commonly be used when we need to confirm password entered by the user at the registration time. The data is always case sensitive. Example: <asp: Required. Field. Validator ID="Required. Field. Validator 2" runat="ser ver" Style="top: 145 px; left: 367 px; position: absolute; height: 26 px; width: 162 px" Error. Message="password required" Control. To. Validate="Text. Box 3"> </asp: Required. Field. Validator>

Range. Validator Control • The Range. Validator Server Control is another validator control, which

Range. Validator Control • The Range. Validator Server Control is another validator control, which checks to see if a control value is within a valid range. The attributes that are necessary to this control are: Maximum. Value, Minimum. Value, and Type. • Example: <asp: Range. Validator ID="Range. Validator 1" runat="server" Style="top: 194 px; left: 365 px; position: absolute; height: 22 px; width: 105 px“ Error. Message="Range. Validator" Control. To. Validate="Text. Box 4" Maximum. Value="100" Minimu m. Value="18" Type="Integer"> </asp: Range. Validator>

Regular. Expression. Validator Control • • A regular expression is a powerful pattern matching

Regular. Expression. Validator Control • • A regular expression is a powerful pattern matching language that can be used to identify simple and complex characters sequence that would otherwise require writing code to perform. Using Regular. Expression. Validator server control, you can check a user's input based on a pattern that you define using a regular expression. It is used to validate complex expressions. These expressions can be phone number, email address, zip code and many more. Using Regular Expression Validator is very simple. Simply set the Validation. Expression property to any type of expression you want and it will validate it. If you don't find your desired regular expression, you can create your custom one. Example to check the email id format: <asp: Regular. Expression. Validator ID="Regular. Expression. Validator 1" runat="server" St yle="top: 234 px; left: 366 px; position: absolute; height: 22 px; width: 177 px" Error. Message="Regular. Expression. Validator" Control. To. Validate="Text. Box 5" Validation. Expression="w+([-+. ']w+)*@w+([-. ]w+)*. w+([-. ]w+)*"> </asp: Regular. Expression. Validator>

Custom. Validator Control • The Custom. Validator Control can be used on client side

Custom. Validator Control • The Custom. Validator Control can be used on client side and server side. Java. Script is used to do client validation and we can use any. NET language to do server side validation. <asp: Custom. Validator ID="Custom. Validator 1" runat="server" On. Server. Valid ate="User. Custom. Validate" Control. To. Validate="Text. Box 1" Error. Message="User ID should have atleast a capital, small and digit and s hould be greater than 5 and less than 26 letters" Set. Focus. On. Error="True"> </asp: Custom. Validator>

Validation. Summary • ASP. NET has provided an additional control that complements the validator

Validation. Summary • ASP. NET has provided an additional control that complements the validator controls. • The Validation. Summary control is reporting control, which is used by the other validation controls on a page. • You can use this validation control to consolidate errors reporting for all the validation errors that occur on a page instead of leaving this up to each and every individual validation control. • The validation summary control will collect all the error messages of all the non-valid controls and put them in a tidy list. <asp: Validation. Summary ID="Validation. Summary 1" runat="server" style="top: 390 px; left: 44 px; position: absolute; height: 38 px; wid th: 625 px" />