1.html
<input id= "Input_num" type= "text"/>
2.js
<script src= "Http://libs.baidu.com/jquery/1.11.1/jquery.min.js" ></script>
<script>
$ (function () {
var num_reg =/^[0-9]\d*$/;
var TOOLFN = {
Fmoney:function (s, N) {
n = n > 0 && n < 20? N:2;
s = parsefloat ((S + "). Replace (/[^\d\.-]/g, ')"). ToFixed (n) + ';
var L = s.split ('. ') [0].split ('). Reverse (),
r = S.split ('. ') [1],
t = ';
for (var i = 0; i < l.length; i++) {
T + = L[i] + ((i + 1)% 3 = = 0 && (i + 1)! = L.length? ‘,‘ : ‘‘);
}
Return T.split ("). Reverse (). Join (') + '. ' + R;
},
Rmoney:function (s) {
Return parsefloat (S.replace (/[^\d\.-]/g, "));
}
};
$ (' #input_num '). focus (function () {
This.value = This.value? Toolfn.rmoney (This.value): ";
});
$ (' #input_num '). KeyUp (function () {
if (! Num_reg.test (This.value)) {
$ (' #input_num '). Val (');
}
});
$ (' #input_num '). blur (function () {
if (Num_reg.test (This.value)) {
This.value = This.value? Toolfn.fmoney (this.value, 0): ";
}
})
})
</script>
Input price Format check