본문 바로가기
jQuery

문자열 숫자체크

by 캡틴노랑이 2015. 9. 1.
반응형

jQuery function to to format number with commas and decimal
http://stackoverflow.com/questions/14075014/jquery-function-to-to-format-number-with-commas-and-decimal
문자열 숫자체크
,제거 후 자리수 계산하여 , 다시 삽입
function ReplaceNumberWithCommas(ctrl) {
            yourNumber = ctrl.value;
            yourNumber = yourNumber.replace(/,/g, '');
            var n = yourNumber.toString().split(".");
           
            n[0] = n[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
           
            ctrl.value =n.join(".");           
        }
반응형

댓글