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="http://code.jquery.com/jquery-1.10.2.js"></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.');
            }
        })
    })
</script>

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

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

Comments

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 asp.net inside GridView in c#

go to top image