正则校验规则,保留小数点后两位的方法?
巴扎黑
巴扎黑 2016-11-08 14:46:44
0
1
688

html:

<input type="text" keyinput="floating" >

JS:

$('body').delegate("input[keyinput]", "keyup", function(e) {

    var value = $(this).val();                
            RegStr = '^[\\+\\-]?\\d+\\.?\\d{0,2}'; // 保留小数点后2位
            $(this).val(value.match(new RegExp(RegStr, 'g')));            return;                    
    });

keyup, 每输入一次字符都进行一次校验。 限制为小数点后两位,多出来就自动清掉。 这部分功能正常。

问题是:负号,出不来。


巴扎黑
巴扎黑

reply all(1)
phpcn_u29

/^[-+]?\d*[.]?\d{0,2}$/

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template