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>
<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
Post a Comment