Sponsored Links
VB.NET 2005 Tutorials
- VB.NET 2005 Free Training
- Shared Assembly
- The .NET Framework Architecture Part 1
- Tracing VB.NET Windows Application
- The .NET Framework Architecture Part 2
- VB.NET Windows Application Testing
- Implementing Inheritance
- The File Types Editor
- Visual Studio.NET Namespaces
- Differences between VB.NET 1.0 and VB.NET 2.0
- Visual Studio Windows Forms Designer
- Introducing VB.NET Windows Forms
- Event Handling In Visual Basic .NET
- Exploring the Forms Designer generated code
- Building Graphical Interface elements
- Microsoft .NET Creating Installation Components
- Application Class and Message Class
- Visual Studio Adding Controls to Windows Form
- Common Controls and Handling Control Events
- Implementing Class Library Object
Tutorials
VB.NET 2005VB.NET Validation Controls
Table of Contents
VB.NET Validation Controls
VB.NET Validation Controls - Page 2
VB.NET Validation Controls - Page 3VB.NET Validation Controls
VB.NET Validation Controls
In this tutorial you will learn about User Input Validation, Required Field Validators, Comparison Validators, Range Validators, Regular Expression Validator, Custom Validators, ErrorProvider, Enabling Controls Based On Input and Other Properties of Validation.
User Input Validation
While any application can be designed with sound logic and good technology and can deliver high performance with accuracy, some errors could still creep into it. This could be due to wrong inputs by users. While the programmer may have taken care of all the exceptions it could cause a loss of business goodwill if a customer is confronted with an error message after he has input data into a number of fields. All of us are familiar with warnings like “Please enter a valid ZIP” or “Please Enter Your First Name!” and so on!
Thus some client side validations ensure that correct data is sent to the application. We can ensure such validations using validation controls. .NET Framework provides several controls for different types of validations.
The validation Controls that are available in .Net Framework are given below:
|
Control
Description
RequiredFieldValidator
Ensures that the user enters data in the associated data-entry control
CompareValidator
Uses comparison operators to compare user-entered data to a constant value or the value in another data-entry control
RangeValidator
Ensures that the user-entered data is in a range between given lower and upper bounds
RegularExpressionValidator
Ensures that the user entered data matches a regular expression pattern
CustomValidator
Ensures that the user-entered data passes validation criteria that you set yourselfRequired Field Validators
This is one of the simplest controls to use. This validating control makes sure that the users have entered data into a data-entry control. For example, you may want to make sure that users enter their mail id or their credit card number before they proceed to submit the form. The RequireFieldValidator control will ensure that the user will not be able to complete the form submission with null value for the field associated with this control. This control is used to validate the value entered in to one data entry control by comparing it with the data entered in to another control. The ControlToValidate property sets the field to be validated. The ControlToCompare property specifies the control to compare with. You can also validate the data from constant value by setting the property ValueToCompare. When you set both the ControlToCompare and ValueToCompare then ControlToCompare takes precedence.
Value Description
Equal
Checks if the comared values are equal
NotEqual
Checks if the compared values are not equal
GreaterThan
Checks for greater than relationship
GreaterThanEqual
Checks for greater than or equal relationship
LessThan
Checks for Less than relationship
LessThanEqual
Checks for less than or equal relationship
DataTypeCheck
Compares the data types between the value entered into the data-entry control that is validated and the data type specified by the Type propertyThe type property can have any of the following values: A range validator test is used to check if the value entered in the data-entry control is within a specified range of values. The property ControlToValidate is set to the control that contains the data which is to be validated. The property MinimumValue sets the minimum value of the range. The property MaximumValue sets the maximum value of the range. The property Type sets the date type of the values to be compared. All the types of comparisons discussed above are still valid for this also. RegularExpressionValidator control is used to check if the value in a data-entry control matches a pattern defined by a regular expression. You can check even the format of the text entered. Regular expressions are generally made up of test with embedded codes that start with a backslash (\). For instance a simple expression for checking for either a uppercase or lower case alphabet is given by the expression “ \b[A-ZA-z]+\b.
This control allows the developer freedom to define his own validations. The property ClientValidationFunction property sets the name of function or script that will do the validation. This function takes two parameters. The first argument source identifies the source control to validate. The second argument arguments hold the data to validate. CausesValidation is one of the public instance properties of the control class, which specifies whether all controls which require validation gets it when the control gets focus. It returns true if the control causes validation to be performed on any controls requiring validation when it receives focus and false otherwise. Validating event occurs when the control is validating at the time when the control loses the focus if the control’s CausesValidation property is true. Any code executed in response to this event can be used to throw exception if any is found. Validated Event occurs when the control has completed validation. This event occurs if no exception was thrown in the validating event. Clearing up the error provider messages can be done here.
Next Page: VB.NET Validation Controls - Page 2
|

