Alphabets Validation on TextBox in jQuery
In this example, alphabet validation in jQuery “onkeypress” event by TextBox id to accept alphabets only.
Steps –
- First add jquery.min.js library in header section of PHP file.
- Call jQuery function on onkeypress event by id of TextBox as showing in bellow code –
<!DOCTYPE html>
<html>
<head>
<script src="https://codeloveguru.com/master-library/js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#studentname").keypress(function(e) {
var key = e.keyCode;
if (key >= 48 && key <= 57) {
e.preventDefault();
}
});
});
</script>
</head>
<body>
<input type="text" name="studentname" id="studentname">
</body>
</html>
Alphabets Validation on textbox in JS onkeypress
Alphabets Validation on textbox in jQuery