Reputation: 185
I am trying to input only number and block rest of the character. here is my code
<input type="number" maxlength="9" id="poisa" placeholder="依頼申請金額 :" name="budget" onkeypress="return (event.charCode !=8 && event.charCode ==0 || (event.charCode >= 48 && event.charCode <= 57))">
<script>
$(document).ready(function(){
$('#poisa').on("cut copy paste",function(e) {
e.preventDefault();
});
});
</script>
it is working well when caps lock is not on. but when caps lock is on it is taking double byte character like 受取金額
i want to prevent this kinds of characters. How to do it by jquery?
Upvotes: 0
Views: 1548
Reputation: 911
Check out this. https://github.com/kenryanlabso/jquery-key-restrictions
$("#poisa").numbersOnly();
$("#poisa").lettersOnly();
$("#poisa").alphaNumericOnly();
Upvotes: 0
Reputation: 759
Your "onKeyUp" should be something like :
<input type="number" maxlength="9" id="poisa" placeholder="依頼申請金額 :" name="budget" onKeyUp="$(this).val($(this).val().replace(/[^\d]/ig, ''))" />
Note : It will make the other inputs like alphabets or special characters, disappear if entered.
Upvotes: 1