This is my first custom control, which I decided to do, to learn about this topic and to make it easy to work with forms validation data. This control inherits all attributes and methods from the
TextBox class and adds some input and required validations. The validation options are:
- Valid chars validation.
- Invalid chars validation.
- Letters validation.
- Numbers validation.
- Regular expression validation (E-mail, IP, URL, ZIP, Fecha and Custom).
Using the code
ValidText as any other .NET component, can be added to the IDE ToolBox to be put graphically into Windows forms and modify their properties from the properties window in the Validation Category. It can also be used like reference, using its methods and modifying its attributes directly from the code, after generating an instance of its class.
ValitationMode (ValidationTypes): Sets the validation mode to use for the text or data field. This validation mode can be:
MaskString (String): Sets the allowed mask for the input data when
ValidationMode = MaskEdit. Character
# suggests a digit,
A suggests upper letter,
z suggests lower letter,
$ suggests an upper letter, lower letter, or number. Any other character will be seen as a fixed character in the mask. For example: If the
ValidationMode property =
MaskString = ###- (AAA) - ##/aa/AA/&&/$$$, user can be able to write data of
345 - ( ABC ) - 22/ad/CD/Ad/s3G types in the text control.
ValidString (String): Sets the valid and not valid characters allowed when
ShowErrorIcon (Boolean): Sets if the icon and tool tip of the
ErrorProvider is shown in the validation of the data field.
Required (Boolean): Sets if the data field must have at last one character to be validated.
Reference (String): Sets the link between the text control and the data field to get. This property is used to make the validation error messages.
RegExMode (RegExTypes): Sets the regular expression mode to use for the text or data field. This regular expression mode can be:
MessageLanguage (MessageLanguages) : Sets error icon messages language. (
requiredFieldsCheck: This share method of the
ValidText class returns
true if the form you send as parameter has at last one
ValidText control with
Required property =
Text property = “”
Private Sub btnAceptar_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnAceptar.Click
If ValidText.ValidText.requiredFieldsCheck(Me) = True Then
MsgBox("OK!", MsgBoxStyle.Information, Me.Text)
MsgBox("There are required fiels in the form!", _
cancelRequiredFieldsCheck: Lets avoid the required validation of
ValidText controls of the form you send as parameter.
Private Sub btnCancelar_Click(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles btnCancelar.Click
Note: The buttons or others control used to fire these methods need to set their
Causesvalidation property to
FALSE, in order to have access to their events.
Please send me feedback, comments, and suggest to: firstname.lastname@example.org