【JQuery】テキストボックスで数字のみしか入力できないようにする(input)
テキストボックスで数字のみしか入力できないように入力制限をかける方法です。(inputを使用)
javascript
$(function() { $('.text-input').on('input', function() { // 半角変換 var halfVal = $(this).val().replace(/[!-~]/g, function (tmpStr) { // 文字コードをシフト return String.fromCharCode(tmpStr.charCodeAt(0) - 0xFEE0); } ); // 数字以外の不要な文字を削除 $(this).val(halfVal.replace(/[^0-9]/g, '')); }); });
コメントを残す