<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>정규식을 이용한 콤마 제거하기</title>
<script type="text/javascript">
<!--
// 콤마를 제거
function getNumString(s) {
var rtn = parseFloat(s.replace(/,/gi, ""));
if (isNaN(rtn)) {
return 0;
}
else {
return rtn;
}
}
//테스트
console.log("-1,500 => " + getNumString("-1,500"));
console.log("1500 => " + getNumString("1500"));
console.log("1,5,0,0 => " + getNumString("1,5,0,0"));
console.log("-1,50a => " + getNumString("-1,50a"));
console.log("ABCDabcd => " + getNumString("ABCDabcd"));
//-->
</script>
</head>
<body>
</body>
</html>