金额输入验证

//金额输入验证
function validateMoney($this) {
var num = $this.val();
num = num.replace(/[^\d+(\.\d)?$]/g, '');
if (isNaN(num)) {
num = "0";
}
if (num.indexOf(".") > 0) {
var t = num.split(".")[1];
if (t.length > 2) {
num = parseFloat(num).toFixed(2);
}
} else if (num != "") {

num = parseFloat(num);
}
$this.val(num);
}
posted on 2018-02-11 12:42  疯狂的小馒头  阅读(209)  评论(0编辑  收藏  举报