Hi,
If you are using HTML 5 you can do it as :
<input type="text" class="TxtBox" id="txtPhNo" placeholder="Enter Phone No" pattern="[0-9]" />
Refer to this :
http://www.pageresource.com/html5/input-validation-tutorial/[
^]
If not HTML5, then you can do it using JavaScript or Jquery both.
1) JavaScript :
<input type="text" class="TxtBox" id="txtPhNo" placeholder="Enter Phone No" önkeypress="return event.charCode >= 48 && event.charCode <= 57"></input></input>
2) JQuery :
$(document).ready(function() {
$("#txtboxID").keydown(function (e) {
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
(e.keyCode == 65 && e.ctrlKey === true) ||
(e.keyCode >= 35 && e.keyCode <= 39)) {
return;
}
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
});
});
Hope this helps !!
Regards,
Praneet