<input id="firstname" type="text" name="firstname" value=""> <script> firstname.oninput = function() { var str = this.value; firstname.value = str.replace(/([^abcdi])/g, ''); } </script>