Hi nagaraju60,
Chek with the below code.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#txtInput").keypress(function (e) {
if ($("#rbNumeric").is(":checked")) {
return IsNumber(e);
}
if ($("#rbNonNumeric").is(":checked")) {
return IsAlphaNumeric(e);
}
});
});
//add key code that you want to allow user to input
var specialKeys = new Array();
specialKeys.push(8); //Backspace
specialKeys.push(9); //Tab
specialKeys.push(46); //Delete
specialKeys.push(36); //Home
specialKeys.push(35); //End
specialKeys.push(37); //Left
specialKeys.push(39); //Right
function IsNumber(e) {
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
};
function IsAlphaNumeric(e) {
var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
var ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode));
return ret;
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="rbNumeric" type="radio" name="select" value="rbNumeric" /><label for="rbNumeric">Numeric</label>
<br />
<input id="rbNonNumeric" type="radio" name="select" value="rbNonNumeric" /><label
for="rbNonNumeric">AlphaNumeric</label>
<br />
<input name="txtInput" type="text" id="txtInput" />
</div>
</form>
</body>
</html>
Demo
Also refer the below article.