0
0

More than 1 year has passed since last update.

【JavaScript】【Jquery】数値以外入力不可にする※全角数値はOK

Last updated at Posted at 2023-09-20
process.stdin.resume();
process.stdin.setEncoding('utf8');

$('input[name="cost"]').on('input', function() {
    var num = $(this).val().replace(/[0-9]/g,(s) => String.fromCharCode(s.charCodeAt(0)-0xFEE0));
    $('input[name="cost"]').val(num);
    if(!$.isNumeric(num)) {
        alert('数値を入力してください');
        $('input[name="cost"]').val(num.replace(/\D+/g, ''));
    }
})
0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0