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

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -