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#

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

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

How to import CSV files into DataTable in C#

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

go to top image