Letter and Number Validation in JavaScript

Sometimes, you may get business requirement where you need to allows users to enter either letter and numbers, we can validate letters and numbers by using JavaScript very easily.

<script type='text/javascript'>
function letterAndNumberValidation()
var letterAndNumberValue = /^[0-9a-zA-Z]+$/;
alert("Yes you enter letters or numbers only.");
return true;
alert('Only letters and numbers allowed');
return false;
Enter Value: <input type='text' id='txtletter'/>
<input type='button' id="btnSubmit" onclick="letterAndNumberValidation()" value='Submit' />

Leave a Reply

Your email address will not be published. Required fields are marked *