Click here to Skip to main content
Click here to Skip to main content
Go to top

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

Introduction

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.

Properties

  • 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)

Methods

  • 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)
            Me.Close()
        Else
            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
    ValidText.ValidText.cancelrequiredFieldsCheck(Me)
    Me.Close()
    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.

Conclusion

Please send me feedback, comments, and suggest to: ra_luis@yahoo.com

License

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

Share

About the Author

machocr
Web Developer
Costa Rica Costa Rica
Ing. Luis Alberto Ruiz Arauz
Software Engineering / Industrial Engineering
Follow on   Twitter

Comments and Discussions

 
QuestionCan I use this DLL with VB6? Pinmemberlemorlenny23-Feb-09 22:03 
Questionwhat is use of mask field ??? pls say how to use the code Pinmemberrama charan24-Nov-06 6:01 
Generalbig thanks PinmemberDaveMon13-Apr-06 11:09 
GeneralC# version Pinmemberyamabiz15-Feb-06 11:20 
QuestionC# Version??? Pinmember.NET Follower16-Nov-04 19:48 
AnswerRe: C# Version??? PinmemberReader Man San15-Feb-09 21:50 
GeneralBug on line 613 ValidText.vb PinmemberSAN Peter17-May-04 0:42 
GeneralRe: Bug on line 613 ValidText.vb PinmemberRenaud Bédard1-Feb-05 9:37 
GeneralScary photo , man PinmemberAnthony_Yio10-Oct-03 21:04 
GeneralHelp on Email validation Pinmembermubavoice4-Oct-03 22:08 
GeneralRe: Help on Email validation Pinmemberyamabiz15-Feb-06 11:05 
Questioncomments? Pinmembermachocr2-Jun-03 11:36 
AnswerRe: comments? PinmemberLevi Erdmann7-Oct-03 9:34 
GeneralRe: comments? Pinmembermachocr7-Oct-03 11:21 
GeneralRe: comments? PinmemberLevi Erdmann7-Oct-03 11:23 
AnswerRe: comments? PinmemberTimothy Paul Narron6-Jan-04 11:24 
AnswerRe: comments? PinmemberSidney James Fuerte5-Jan-06 21:54 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140905.1 | Last Updated 31 May 2003
Article Copyright 2003 by machocr
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid