in this article, I will show you textbox input validation text or number formate in jquery
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src ="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<input type="text" class="CheckChar" id="txtusername" name="Username " placeholder="Username Enter" value="">
<input type="text" class="CheckNum" id="txtmob" maxlength="10" minlength="10" name="Mobile No." placeholder="Mobile No." value="">
</body>
<script>
$(function(){
$('.CheckChar').on('input', function () {
this.value = this.value
.replace(/[^a-zA-Z]/g, '');
});
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src ="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<input type="text" class="CheckChar" id="txtusername" name="Username " placeholder="Username Enter" value="">
<input type="text" class="CheckNum" id="txtmob" maxlength="10" minlength="10" name="Mobile No." placeholder="Mobile No." value="">
</body>
<script>
$(function(){
$('.CheckChar').on('input', function () {
this.value = this.value
.replace(/[^a-zA-Z]/g, '');
});
$('.CheckNum').on('input', function () {
this.value = this.value
.replace(/[^0-9]/g, '');
});
this.value = this.value
.replace(/[^0-9]/g, '');
});
or :
$(".onlynumber").keypress(function(a) {
</script>
</html>
if (a.which != 8 && a.which != 0 && (a.which < 48 || a.which > 57)) {
return false
}
});
});</script>
</html>
0 Comments
if you have any doubts , please let me know