タグ

ブックマーク / php.o0o0.jp (1)

  • 数字をカンマ区切り設定 | 私的雑録

    $(function () { $('#amount').focusout(function() { var str = $(this).val(); // カンマ除去 str = str.replace(/,/g, ''); // 数字形式 if (str.match(/^(|-)[0-9]+$/)) { // 0消去 str = str.replace(/^[0]+([0-9]+)/g, '$1'); // 数字を3桁区切りでカンマ付与 str = str.replace(/([0-9]{1,3})(?=(?:[0-9]{3})+$)/g, '$1,'); } $(this).val(str); }).focusin(function() { var str = $(this).val(); // カンマ除去 str = str.replace(/,/g, ''); $(this).v

  • 1