javascript - jQuery allow selected characters only keypress function -
hi tried use code limit user's input. problem cannot use return key or enter in keyboard in input box. how can solve problem. im using code:
$("input").keypress( function(e) { var chr = string.fromcharcode(e.which); if ("bcdegkmnqupvxy36789".indexof(chr) < 0) return false; });
to achieve need can add condition if
statement checks return keycode: 13
:
$("input").keypress(function(e) { var chr = string.fromcharcode(e.which); if ("bcdegkmnqupvxy36789".indexof(chr) < 0 && e.which != 13) return false; console.log('allowed'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" name="foo" />
wiki
Comments
Post a Comment