Add the following inside your name Textbox's Leave event: Private Sub txt Name_Leave(sender As Object, e As System. Leave 'If Not A Matching Format Entered If Not Regex. If you are uncertain about the pattern I supplied, have a look here. Just a note, some surnames contain spaces and even hyphens. Sometimes there are even brackets surrounding the code. My surname contains a space and it can get quite frustrating if I am not allowed to enter my correct surname, or that I have to edit my surname not to include a space. In certain cases the international dialling code will also need to be supplied. Compiled _ ) Dim bln Possible Match As Boolean = re Email. Text) If bln Possible Match Then 'Check If Entered Email Is In Correct Format If Not txt Email. Specifically, this tutorial takes the example created in Tutorial 17: Examining the Events Associated with Inserting, Updating, and Deleting and augments the editing and inserting interfaces to include appropriate validation.In Tutorial 17: Examining the Events Associated with Inserting, Updating, and Deleting, we created a page that listed the names and prices of the products in an editable Grid View.If a user makes a data-entry mistake—such as omitting the Product Name field or entering an invalid value for Units In Stock (such as -50) —an exception will be raised from within the depths of the application architecture.While this exception can be gracefully handled as demonstrated in the previous tutorial, ideally the editing or inserting user interface would include validation controls to prevent a user from entering such invalid data in the first place.In order to provide a customized editing or inserting interface, we need to replace the Bound Field or Check Box Field with a Template Field.Template Fields, which were the topic of discussion in Tutorial 12: Using Template Fields in the Grid View Control and Tutorial 13: Using Template Fields in Details View, can consist of multiple templates defining separate interfaces for different row states.
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.
The Template Field's Item Template is used to when rendering read-only fields or rows in the Details View or Grid View controls, whereas the Edit Item Template and Insert Item Template indicate the interfaces to use for the editing and inserting modes, respectively.
In this tutorial, we'll see how easy it is to add validation controls to the Template Field's Edit Item Template and Insert Item Template to provide a more foolproof user interface.
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.