Skip to content

Instantly share code, notes, and snippets.

@arahansa
Created November 29, 2015 18:07
Show Gist options
  • Save arahansa/7dc6ff0c3b354c545bcc to your computer and use it in GitHub Desktop.
Save arahansa/7dc6ff0c3b354c545bcc to your computer and use it in GitHub Desktop.
돈 검증
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8" />
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<input type="text" id="testForm" value="3444" />
<input type="button" onclick="test()" value="테스트" />
<input type="text" id="testForm2" value="3,444" />
<input type="button" onclick="test2()" value="테스트" />
<script>
var reg = /(^[+-]?\d+)(\d{3})/;//정규식 숫자3자리수 콤마
function test(){
console.log("테스트 ");
var money = $("#testForm").val() ;
console.log( money );
while (reg.test(money)) {
money = money.replace(reg, '$1' + ',' + '$2');
}
console.log( money );
}
function test2(){
console.log("테스트 2 ");
var money = $("#testForm2").val() ;
var replacedMoney = Number(money.replace(/[,]/g, ''));
console.log("머니", replacedMoney);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment