How to allow only text in input in jquery

Manideepgoud
Posted by Manideepgoud under jQuery category on | Points: 40 | Views : 1525
Hi,
In the below code am showing how to allow only text without numbers in the input.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
function Validate(validtext) {
validtext.value = validtext.value.replace(/[^a-zA-Z- '\n\r.]+/g, '');
}
</script>
</head>
<body>

<div class="container">
<label>Text:</label>
<input type="text" placeholder="First Name*" name="first_name" class="first_name error_message" onkeyup="Validate(this)" id="validtext">
</div>

</body>
</html>

Hope This code might help you.
Thanks,
Manideep

Comments or Responses

Login to post response