Restrict users for entering special charcters in textbox using Jquery

First of all add the following codes inside your <head> tag ::

<script type="text/javascript" src=""></script>
<script type="text/javascript">
    $(function () {
        $('#btnClick').click(function () {
            var str = $('#txtName').val();
            if (/^[a-zA-Z0-9- ]*$/.test(str) == false) {
                alert('Special Characters are not allowed.');

Then add this code inside your <body> tag ::

Enter Search:<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <asp:Button ID="btnClick" runat="server" Text="Check" />


Popular posts from this blog

Search data in Gridview on Textbox Key press event using JQuery in Asp.Net- C#

Dumps for Microsoft Dynamics CRM MB2-703 Practice Exam Questions Free

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

How to show enlarge image when mouse hover on image or link in Asp.Net(c#) using JavaScript

Show GridView row details in tooltip on mouseover with jQuery using inside GridView in c#

go to top image