控制input框的内容输入为数字

时间:2022-11-22 13:17:19
    <script>
function toNum(v) {
return v.replace(/[^\d.]/g, '').replace(/^\./g, "").replace(/\.{2,}/g, ".").replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
}
$("[name=Amount],[name=Discount]").keyup(function () {
$(this).val(toNum($(this).val()));
});
$("[name=Amount],[name=Discount]").blur(function () {
$(this).val(toNum($(this).val()) - 0);
});
</script>

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVAAAABmCAIAAAAS3l6KAAAFT0lEQVR4nO3dSXLbOhRGYe8JW8FSMM0qsBJUaRmZ0HNtQ1NlwEuiYSMqIinZ//kGr2KriUuXhyAp5+nrDkDG17t/AADnIXhACMEDQggeEELwgBCCB4QQPCCE4AEhX38ByCB4QAjBA0IenMNfr9dzTi3wLoxYwThlglfHiBUQPAwjVkDwMIxYAcHDMGIFBA/DiBUQPAwjVkDwMIxYAcHDMGIFBA/DiBUQPAwjVrBX8Cm4kIqvu+idj929+daovy2F5j793ULKz9hF72M3/QuGv3Xe9GnxyMPgh1HMfL96zWdHNf985R2bL3GIHLxzay/3c8F30Tvvm+Tz9mJ/qvYAxSbT35yCC7F8yMxPt7Bpze1H8MgTwTeTa2aQpzKzQy4mU02vi96FwOCOdsQKP+6q6312F72Pqf5PVz3F7F7AOR+7hS2MFX5HzwW/ttaPQ4jT4778uLlNZumJsZcc/PoLvbI1lNX5GEOVWxf90GcVvFVZDr1cl/stp9we7M/1FsEKv6PV4OshT3bW7X3zCr8YfHFbCnmT4cD+WDn49Rd52wo/P60UnN3YLu7VgfqYaQrOuRDCuJin6NtD+8W1nXX+f+2wwve2BD8uBMWKUDye5o+y/yH90pn5TPB9vcND++DHaeddiHMh2d6g3tIWFozNV41Q2hR8CN6FNHPeVZxp2dWXtUP6LgbvXUjl2l5a+j5etWPwFnd9ea34ahK83Zavw1fnd/XA+/s2K8vCdldse9juwYj7CY9HZvPn4s0l+4UVvou+2hnUO25KP9LrV+nH6vIKXzxPM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d+(.\d+)? 数字的正则

相关文章