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

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

How to import CSV files into DataTable in C#

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

go to top image