kalpana jaiswal

kalpana jaiswal

  • NA
  • 45
  • 9.8k

disable characters while entering contact number in textbox

Mar 13 2016 4:05 AM
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" src="JavaScripts/jquery.js"></script>
<script type="text/javascript">
$(function () {
$(".xyz").keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
}
else {
var key = e.keyCode;
}
if (!((key == 8) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
e.preventDefault();
}
});
});
</script>
 
 

<asp:TextBox ID="txtCont" class="xyz" runat="server"></asp:TextBox></td>
<td colspan="1">
<asp:RequiredFieldValidator ID="rfvtxtCont" runat="server" ControlToValidate="txtCont" ForeColor="Red" ErrorMessage="Contact No is mandatory" ToolTip="Please enter the Contact No" Text=" * " SetFocusOnError="true" ValidationGroup="Register"></asp:RequiredFieldValidator></td>
<td>
<asp:RegularExpressionValidator ID="regContact" runat="server" ErrorMessage="Contact no shhould be 10 digit number" SetFocusOnError="True" Text="*" ToolTip="Contact no shhould be 10 digit number" ValidationGroup="Register" ValidationExpression="^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$" ControlToValidate="txtCont"></asp:RegularExpressionValidator>
 
 

Answers (1)