仿支付宝金额输入规则
<!-- 正则 -->
<body>
<input type="text" id="pay">
<script>
document.getElementById("pay").addEventListener("input", function() {
this.value = this.value.replace(/(^00)/,"").replace(/^[^\d]*(\d*\.?\d{0,2})(.*)?$/, "$1");
}, false);
</script>
</body>
<!-- 截取字符串 -->
<body>
<input type="text" id="pay">
<script>
document.getElementById("pay").addEventListener("input", function() {
this.value = this.value.replace(/^[^\d]$/,"");
this.value.substr(0, 2) == "00" && (this.value = "");
this.value = this.value.split(".")[0] + (this.value.indexOf(".") > 0 ? ("." + this.value.split(".")[1].substr(0, 2)) : "");
}, false);
</script>
</body>
浙公网安备 33010602011771号