Custom textbox validating user input
Each control that accepts free-form user input has a Validating event that will occur whenever the control requires data validation.
In the Validating event-handling method, you can validate user input in several ways.
The masking language that is used by Masked Text Box is very flexible.
It allows you to specify required characters, optional characters, literal characters, such as hyphens and parentheses, currency characters, and date separators.
The Format event on a data binding can be used to reformat incoming data to comply with the mask, and the Parse event can be used to reformat outgoing data to comply with the specifications of the data field. If you want full programmatic control over validation, or need to perform complex validation checks, you should use the validation events built into most Windows Forms controls.
If you need to require users to enter data in a well-defined format, such as a telephone number or a part number, you can accomplish this quickly and with minimal code by using the Masked Text Box control.
A is a string made up of characters from a masking language that specifies which characters can be entered at any given position in the text box. If the user types an incorrect entry, for example, the user types a letter when a digit is required, the control will automatically reject the input.
In this case, to perform validation in the Validated event, change the control's Data Source Update Mode property (under (Databindings)\(Advanced)) from On Validation to Never, and add So when does a control's data get validated? You can use either implicit or explicit validation, depending on the needs of your application.
The implicit validation approach validates data as the user enters it.