After you drag and drop a Masked Text Box on a Form, the Masked Text Box looks like Figure 1. The following code snippet adds a Masked Text Box control to the current Form.

Once a Masked Text Box is on the Form, you can move it around and resize it using mouse and set its properties and events. The easiest way to set properties is from the Properties Window.

So I immediately tried the Masked Text Box that would fit my needs (with a Mask like "€ 00000.00"), if it weren't for the focus and the length of the mask.

I can't predict how big the numbers are my customer is going to enter into the app.

Figure 1 - These objects will determine if all our data is valid or not. Clear() 'Clear Text Box Name Valid = False 'Boolean = False Else Name Valid = True 'Everything Fine End If End Sub Easy one to start with. Focus() 'Set Focus To Text Box End If End Sub Private Sub txt Email_Lost Focus(sender As Object, e As System. Lost Focus Validate Email() 'Check Email Validity End Sub The expression may look horrible to the layman's eye, but look closer. To check if the user has entered an email that actually exists, you will have to find a different way such as to send a of some sorts.

Based on each of these variables' values, we will know if the data is correct or not. The Leave event fires when the control loses focus. As you can see, Regular Expressions are a vital tool to have at your disposal, so become good friends with them.

So, what I am trying to say is: make sure you understand other cultures, or be aware of people with uncommon names. Using Regular expressions here, is basically the standard, even though it is a bit messy. Focus() 'Return Focus End If End Sub Here, I created a separate function to do all the work.

Add this to validate the surname textbox: Private Sub txt Surname_Leave(sender As Object, e As System. Leave 'Create A Pattern For Surname Dim str Surname As String = "^[a-z A-Z\s] $" Dim re Surname As New Regex(str Surname) 'Attach Pattern To Surname Textbox 'Not A Match If Not re Surname. Add the following code to validate your phone number textbox: 'Function To Check Phone Number Validity Public Function Validate Phone(By Val str Phone Num As String) As Boolean ''Create Reg Exp Pattern Dim str Phone Pattern As String = "^[1-9]\d-[1-9]\d-\d$" 'Create Reg Ex Object Dim re Phone As New Regex(str Phone Pattern) 'Something Typed In If Not String. This function is later called inside the textbox's Lost Focus event, which also fires when a control loses the focus. Keep in mind that each country has its own domain name, which sometimes will look like: Private Sub Validate Email() 'Set Up Reg Exp Pattern To Allow Most Characters, And No Special Characters Dim re Email As Regex = New Regex("([a-z A-Z0-9_\-\.] )@((\[[0-9]\.[0-9]\.[0-9]\." _ ")|(([a-z A-Z0-9\-] \.) ))([a-z A-Z]|[0-9])", _ Regex Options.

Is Null Or Empty(str Phone Num) Then Phone Valid = re Phone. Text) Then 'Call Phone Validation Function Message Box. I set up my Expression to allow only numbers, but in the format I explained earlier.

Is Match(str Phone Num) 'Check Validity Else Phone Valid = False 'Not Valid / Empty End If Return Phone Valid 'Return True / False End Function Private Sub txt Tel_Lost Focus(sender As Object, e As System. If it isn't valid input, it will clear the textbox and give it the focus again; if it is valid, the Phone Valid variable gets updated to true.

I am doing an Financial Winforms application and am having some trouble with the controls.

My customer needs to insert decimal values all over the place (Prices, Discounts etc) and I'd like to avoid some of the repeating validation.

Sometimes people are just trying to be funny, or they are literally trying to break your program. If the data is indeed only alphabetic letters (no symbols, no numbers or any other punctuation characters) the test succeeds and stores True inside the Name Valid variable. This is because it becomes more legible than just a normal set of numbers.