Hey chetan,
Please refer below sample.
HTML
<div>
<asp:TextBox runat="server" ID="txtName" />
<asp:Button Text="Check" runat="server" OnClick="Check" />
</div>
Namespaces
C#
using System.Text.RegularExpressions;
VB.Net
Imports System.Text.RegularExpressions
Code
C#
protected void Check(object sender, EventArgs e)
{
bool isValid = true;
bool isValid1 = true;
Regex regex = new Regex(@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
string[] values = txtName.Text.Trim().Split(' ');
for (int i = 0; i < values.Length; i++)
{
isValid = regex.IsMatch(values[i].Trim());
isValid1 = !regex.IsMatch(values[i].ToString().Trim()); ;
if (isValid)
{
Response.Redirect("addlisting.aspx");
break;
}
}
if (isValid1 && IsValid)
{
Response.Redirect("addlistingpost.aspx");
}
}
VB.Net
Protected Sub Check(ByVal sender As Object, ByVal e As EventArgs)
Dim isValid As Boolean = True
Dim isValid1 As Boolean = True
Dim regex As Regex = New Regex("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")
Dim values As String() = txtName.Text.Trim().Split(" "c)
For i As Integer = 0 To values.Length - 1
isValid = regex.IsMatch(values(i).Trim())
isValid1 = Not regex.IsMatch(values(i).ToString().Trim())
If isValid Then
Response.Redirect("addlisting.aspx")
Exit For
End If
Next
If isValid1 AndAlso IsValid Then
Response.Redirect("addlistingpost.aspx")
End If
End Sub
Screenshot