Created
December 19, 2012 08:08
-
-
Save lequinharay/4335202 to your computer and use it in GitHub Desktop.
フォームの入力値を数値のみに制限するjavascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
フォームの入力値を数値のみに制限するjavascript | |
web上に落ちてたものから以下の点だけ変えた。 | |
・keyCodeがfirefoxで上手く動かなかったのでwhichを使用 | |
・deleteとか矢印キーによる移動は活かしておきたかった | |
<input class="no-numeric" style="ime-mode: disabled" /> | |
の様にして使う | |
*/ | |
$(function(){ | |
$('.no-numeric').keypress(function(e){ | |
if((e.which < "0".charCodeAt(0) || "9".charCodeAt(0) < e.which) && e.which != 8 && e.which != 0) { | |
return false; | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment