[JS] 금액 콤마
//콤마찍기
function comma(str) {
str = String(str);
return str.replace(/(\d)(?=(?:\d{3})+(?!\d))/g, '$1,');
}
//콤마풀기
function uncomma(str) {
str = String(str);
return str.replace(/[^\d]+/g, '');
}
//값 입력시 콤마찍기
function inputNumberFormat(obj) {
obj.value = comma(uncomma(obj.value));
}
//<input type="text" onkeyup="inputNumberFormat(this)" />
출처 : http://dlevelb.tistory.com/829
댓글
댓글 쓰기