Click here to Skip to main content
15,889,315 members
Articles / Programming Languages / Visual Basic
Article

Ready to use custom textbox with validation properties

Rate me:
Please Sign up or sign in to vote.
4.27/5 (17 votes)
10 Mar 20052 min read 83.1K   883   24   6
Use of this control will eliminate various common validation issues in a form.

Image 1

Introduction

glblControl Textbox

The use of this control eliminates various common validation issues in a form. Properties available with this control are:

  • Required: Sets the field as required for validation. Required textbox’s background color will be changed to Old Lace.
  • ShowErrorIcon: It is either True or False, it shows a flashing icon. If the required property is set to true and the field is left blank, it will show a red flashing icon. If invalid value is entered, it will flash a yellowish icon.
  • ValidationMode: Sets the validation mode to use. They are the following:
    • None
    • Any value
    • Valid characters e.g. “$1234567890.,”
    • Invalid characters e.g. “@#$%’”^&*”
    • Letters
    • Only alphabets (includes “ , ; . ”)
    • Numbers
    • Only numbers (includes “.”)
  • Textbox (valid/invalid sharacters): Sets this property with valid/invalid characters as per the ValidationMode property.

Events handled

  • TextChanged
  • KeyPress
  • Validating
  • Validated
  • Enter
  • Leave

Limitations: It can check for the form level required property for only those controls where Container level is less than or equal to 4. I.e., if the textbox is in Panel4, under Panel3, under Panel2, under Panel1 under FORM, the form level required property will not be checked when exiting form without any input in the textbox.

Pointing to a yellowish or red error icon will show you tips as to what has gone wrong. The only required code in the form is as follows:

On the OK button:

VB
If glblControls.TextBox.requiredFieldsCheck(Me) = True Then
    MsgBox("OK!", MsgBoxStyle.Information, Me.Text)
    Me.Close()
Else
    MsgBox("There are required fields in the form!", 
       MsgBoxStyle.Exclamation, Me.Text)
End If

On the Cancel button:

VB
glblControls.TextBox.cancelrequiredFieldsCheck(Me)
Me.Close()

glblControl Masked Textbox

This is a very easy to use Masked Textbox for fixed length strings like phone numbers, social security, driver license, etc.

  • The "#" character in the mask is used for digit only.
  • The "&" character accepts letters only.
  • The "!" character accepts a letter or digit.
  • You can use any mask symbol, letter and digit other than # & and !.

E.g. ###-&!/&&(###) ###-!!!! &&XXX##Z12&&&

Using the component

Set the mask property with any combination of characters. At run time, you can read the unformatted Text property to read only the user input. The Text property returns the formatted string.

Image 2

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


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey12-Mar-12 22:26
professionalManoj Kumar Choubey12-Mar-12 22:26 
GeneralMask Pin
kiquenet.com6-Aug-08 2:07
professionalkiquenet.com6-Aug-08 2:07 
GeneralCorrect number of points in a numeric format Pin
alavitiricchiarazio2-Nov-05 3:17
alavitiricchiarazio2-Nov-05 3:17 
GeneralRe: Correct number of points in a numeric format [modified] Pin
BarryGSumpter16-Dec-06 11:43
BarryGSumpter16-Dec-06 11:43 
Hi alavitiricchiarazio.

Can you please post the changes here so we can add them as well?

-----

The decimal point has always been a problem. Especially in a MaskedEdit control.

So my thought is to write a specific control only for decimals or perhaps decimal with currency sign.

To me the cursor position should always be just to the left of the decimal point until the number of place to the left of the decimal have been entered or the decimal key has been pressed.

Then the cursor position should change to just to the right side of the decimal and keep moving to the right on each numeric character entered until the number of places to the right of the decimal has been reached.

In addition, the decimal point keydown event is to select the numbers to the right of the decimal for editing.

_____.__ = C2 or Currency with 2 decimal places currently null or no value


When entering a 1.5 - the decimal keydown should select the numbers to the right of the decimal for editing.

esc key to deselect the selected text
the arrow key to deselect the selected text and move once to the right.

etc.

GeneralI had made some change Pin
aiway27-Mar-05 19:38
aiway27-Mar-05 19:38 
GeneralNice! About Formatting Dates Pin
Bill Gerold18-Mar-05 3:27
Bill Gerold18-Mar-05 3:27 

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.