<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="ButtonOk" runat="server" Text="OK" OnClick="ButtonOk_Click" />
<br /><br />
<asp:Label ID="Label5" runat="server"></asp:Label>
Write the code on button click where you want to check validateion. First add the following namespace.
using System.Text.RegularExpressions;
protected void ButtonOk_Click(object sender, EventArgs e)
{
if (Regex.IsMatch(TextBox1.Text, @"^[a-zA-Z0-9\s.\?\,\'\;\:\!\-]+$"))
{
Label5.Text = "Ok Fine!";
}
else
{
Label5.Text = "Special Characters are not allowed";
}
}