VB.Net Regular Expressions

Regular expressions can be very useful tools they allow you to compare any input to a set layout, and content criteria, in this example an email address is used. This is a very simple example as I f

ITPro Today

October 26, 2003

1 Min Read
ITPro Today logo

Regular expressions can be very useful tools they allow you to compare any input to a set layout, and content criteria, in this example an email address is used. This is a very simple example as I found that when I first looked at regular expressions people had a tendency to overcomplicate them.on a button clickPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickconstruct youre regular expression Dim emailregex As Regex = New Regex("[a-zA-Z0-9]+@[a-zA-Z0-9]+.")check if the input matches youre required criteria Dim ismatch As Boolean = emailregex.IsMatch(TextBox1.Text)display the result message If ismatch Then lblValid.Text = "Validated" Else lblValid.Text = "Not Validated" End If End SubThe regular expression is formed by putting together different criteria, this one breaks down as a-zA-Z-9 Which is any string in upper or lower case.+@ there must be an @ symbol at this point in the stringa-zA-Z-9 Again any string in upper or lower case.+. There must be at least one . at this pointObviously this is not the strictest validation possible but it does offer a quick and fairly accurate validation that is easily customizable.

Read more about:

Microsoft
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like