Please refer below sample.
HTML
<table>
<tr>
<td><asp:TextBox ID="txtInput" runat="server" /></td>
<td><asp:Button Text="Submit" ID="btnSubmit" runat="server" OnClick="Validate" /></td>
</tr>
<tr>
<td><asp:Label ID="lblOutput" runat="server" ForeColor="Red" /></td>
</tr>
</table>
Namespace
C#
using System.Text.RegularExpressions;
VB.Net
Imports System.Text.RegularExpressions
Code
C#
protected void Validate(object sender, EventArgs e)
{
string input = txtInput.Text;
Regex rgxEmailId = new Regex(@"([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
Match emailMatch = rgxEmailId.Match(input);
if (emailMatch.Success)
{
lblOutput.Text = "Email Address not allowed.";
return;
}
Regex rgxMobileNo = new Regex(@"^([0-9]{10})$");
Match mobileNoMatch = rgxMobileNo.Match(input);
if (mobileNoMatch.Success)
{
lblOutput.Text = "Mobile number not allowed.";
return;
}
Regex rgxURL = new Regex(@"^(www|http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$");
Match urlMatch = rgxURL.Match(input);
if (urlMatch.Success)
{
lblOutput.Text = "URL not allowed.";
return;
}
}
VB.Net
Protected Sub Validate(ByVal sender As Object, ByVal e As EventArgs)
Dim input As String = txtInput.Text
Dim rgxEmailId As Regex = New Regex("([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$")
Dim emailMatch As Match = rgxEmailId.Match(input)
If emailMatch.Success Then
lblOutput.Text = "Email Address not allowed."
Return
End If
Dim rgxMobileNo As Regex = New Regex("^([0-9]{10})$")
Dim mobileNoMatch As Match = rgxMobileNo.Match(input)
If mobileNoMatch.Success Then
lblOutput.Text = "Mobile number not allowed."
Return
End If
Dim rgxURL As Regex = New Regex("^(www|http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$")
Dim urlMatch As Match = rgxURL.Match(input)
If urlMatch.Success Then
lblOutput.Text = "URL not allowed."
Return
End If
End Sub
Screenshot