Here is the code to allow only characters in textbox using javascript in asp.net
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
<title></title>
<script type=”text/javascript”>
function AllowAlphabet(e)
{
isIE = document.all ? 1 : 0
keyEntry = !isIE ? e.which : event.keyCode;
if (((keyEntry >= ’65′) && (keyEntry <= ’90′)) || ((keyEntry >= ’97′) && (keyEntry <= ’122′)) || (keyEntry == ’46′) || (keyEntry == ’32′) || keyEntry == ’45′)
return true;
else
{
alert(‘Please Enter Only Character values.’);
return false;
}
}
</script>
<head runat=”server”>
<title></title>
<script type=”text/javascript”>
function AllowAlphabet(e)
{
isIE = document.all ? 1 : 0
keyEntry = !isIE ? e.which : event.keyCode;
if (((keyEntry >= ’65′) && (keyEntry <= ’90′)) || ((keyEntry >= ’97′) && (keyEntry <= ’122′)) || (keyEntry == ’46′) || (keyEntry == ’32′) || keyEntry == ’45′)
return true;
else
{
alert(‘Please Enter Only Character values.’);
return false;
}
}
</script>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:TextBox ID=”TextBox1″ runat=”server” onkeypress=”return AllowAlphabet(event)” ></asp:TextBox>
</div>
</form>
</body>
</html>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:TextBox ID=”TextBox1″ runat=”server” onkeypress=”return AllowAlphabet(event)” ></asp:TextBox>
</div>
</form>
</body>
</html>
Comments
Post a Comment