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. You could say that a program's testers are supposed to do this; yes, they should - nobody else should. If not, if there is even just one unallowed character that is not supposed to be there, the Match method will return False. Instead of you having to loop through each character to determine what that character is, you simply need the correct Regular Expression pattern. Clear() Surname Valid = False Else Surname Valid = True End If End Sub It is basically the exact same code for the Name box, but I just included the capability to comprehend a space character as well. People expect to enter a phone number in a format similar to this: ###-###-####. : D Private Sub Data Grid View1_Cell End Edit(By Val sender As System. Data Grid View Cell Event Args) Handles Data Grid View1. Column Index = 0) Then ' Checking numeric value for Column1 only Dim value As String = Data Grid View1.
What you have to do instead is change the value in the editing control (remembering not to cancel the event). This means that as a programmer, you have the power to supply the exact pattern for the input you desire in any text input field. Again, certain special characters are obviously not allowed. They make use of a pattern matching system to match the input with a certain pattern of data.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.