<input id="cashMoney" type="number" maxlength="10" placeholder="請輸入金額" />
<script> $(function(){ $('#cashMoney').bind('input propertychange',amountVal ); }); function amountVal(){ var replyGold=document.getElementById("cashMoney"); var regStrs = [ ['[^\\d\\.]+$', ''], //禁止錄入任何非數字和點 ['\\.(\\d?)\\.+', '.$1'], //禁止錄入兩個以上的點 ['^(\\d+\\.\\d{2}).+', '$1'] //禁止錄入小數點後兩位以上 ]; for(i=0; i<regStrs.length; i++){ var reg = new RegExp(regStrs[i][0]); replyGold.value = replyGold.value.replace(reg, regStrs[i][1]); } } </script>