1 $("#batch_diff_percent").keyup(
function () {
2 var reg = $(
this).val().match(/\d+\.?\d{0,2}/
);
3 var txt = ''
;
4 if (reg !=
null) {
5 txt = reg[0
];
6 }
7 $(
this).val(txt);
8 }).change(
function () {
9 $(
this).keypress();
10 var v = $(
this).val();
11 if (/\.$/
.test(v))
12 {
13 $(
this).val(v.substr(0, v.length - 1
));
14 }
15 });
相关资源:jquery控制input只能输入数字和小数点,并且只能有一个小数点,小数点前第一位不能为0