Regular Expression:
"\d+" : It will search for numbers in a given string.
[abc] : Find any character between the brackets
[^abc] : Find any character NOT between the brackets
[0-9] : Find any character between the brackets (any-digit)
[^0-9] : Find any character NOT between the brackets(any non-digit)
(x|y) : Find any of the alternatives specified.
{n,m}: Matches the previous element at least n times, but no more than m times.
^ : Match the beginning of the string
Validating Email Address Code:
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim regex As Regex = New Regex("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)")
Dim isValid As Boolean = regex.IsMatch(TextBox1.Text)
If isValid Then
Label2.Text = "Valid"
Label2.BackColor = Color.Green
Else
Label2.Text = "InValid"
Label2.BackColor = Color.Red
End If
End Sub
End Class
"\d+" : It will search for numbers in a given string.
[abc] : Find any character between the brackets
[^abc] : Find any character NOT between the brackets
[0-9] : Find any character between the brackets (any-digit)
[^0-9] : Find any character NOT between the brackets(any non-digit)
(x|y) : Find any of the alternatives specified.
{n,m}: Matches the previous element at least n times, but no more than m times.
^ : Match the beginning of the string
Validating Email Address Code:
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim regex As Regex = New Regex("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)")
Dim isValid As Boolean = regex.IsMatch(TextBox1.Text)
If isValid Then
Label2.Text = "Valid"
Label2.BackColor = Color.Green
Else
Label2.Text = "InValid"
Label2.BackColor = Color.Red
End If
End Sub
End Class