Click here to Skip to main content
13,445,555 members (33,865 online)
Click here to Skip to main content
Add your own
alternative version


53 bookmarked
Posted 30 May 2003

TextBox whith Validation Functions and MaskEdit

, 30 May 2003
Rate this:
Please Sign up or sign in to vote.
Custom control that inherits from TextBox class and adds input validation functions, required validation functions and MaskEdit.

Sample screenshot


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:

  • None.
  • Valid chars validation.
  • Invalid chars validation.
  • Letters validation.
  • Numbers validation.
  • MaskEdit.
  • 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: None, VaidChars, InvalidChars, Letters, Numbers, MaskEdit and RegEX.
  • 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 = MaskEdit and 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 ValidationMode = ValidChars, InvalidChars or RegEx.
  • 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: Custom, Email, URL, IP, Date or ZIP.
  • MessageLanguage (MessageLanguages) : Sets error icon messages language. (English, Español)


  • 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 = TRUE and 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!", _
                          MsgBoxStyle.Exclamation, Me.Text)
        End If
    End Sub
  • 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
    End Sub

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:


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Costa Rica Costa Rica
Ing. Luis Alberto Ruiz Arauz
Software Engineering / Industrial Engineering

You may also be interested in...

Comments and Discussions

GeneralHelp on Email validation Pin
mubavoice4-Oct-03 22:08
membermubavoice4-Oct-03 22:08 
GeneralRe: Help on Email validation Pin
yamabiz15-Feb-06 11:05
memberyamabiz15-Feb-06 11:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180314.2 | Last Updated 31 May 2003
Article Copyright 2003 by machocr
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid