如何在jquery中验证钱 [英] how to validate for money in jquery

查看:101
本文介绍了如何在jquery中验证钱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在jquery中验证资金,我可以输入的最大金额为9999.99 所以我的要求是: 1.它应该只允许数字和一个点 2.最大长度为7(包括点) 3.在点最大长度为4之前 4.点最大长度为2

how to validate for money in jquery where max amount i can enter is 9999.99 so my requirements are: 1.it should allow only digits and one dot 2.max length is 7(including dot) 3.before dot max length is 4 4.after dot max length is 2

当前,我的文本框只允许数字和一个点,其代码如下:

currently my textbox allows only digits and one dot with the following code

$('#txtpaymentamnt, #txttenderamt').on("keypress", function (e) {
    alert(e.which);
    if (e.which != 8 && e.which != 0 && ((e.which < 48 || e.which > 57) && e.which != 46)) {
        e.preventDefault();
    }

推荐答案

您可以使用正则表达式:/^\d{0,4}(\.\d{0,2})?$/

You can do this with a regular expression: /^\d{0,4}(\.\d{0,2})?$/

以下是请求的小提琴

这篇关于如何在jquery中验证钱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆