<input type="text" id="priceStr" class="sale-input com-input money-input" value="$!{status.value}" name="${status.expression}" maxlength="12"/>
js代码
$.validator.addMethod("price", function(value, element) {
var length = value.length;
var flag = false;
if(value.indexOf(".") == length - 1){
flag = false;
}else{
flag = true;
}
var price = /^[0-9]{1,9}([.]{1}[0-9]{1,2})?$/;
if(value == 0 || value > 999999999.99){
flag = false;
}
return this.optional(element) || (flag && price.test(value));
}, "请填写正确的价格,小数精确2位"); //这里用了jquery-validate.js验证插件
$(".btn-sale").click(function(){
$(".money-input").rules("add", {
required: true,
price:true,
messages: {
required: "请填写价格",
}
});
$('.sale-form').validate();
});
$('.sale-form').validate({
rules: {
priceStr: {
required : true
}
},
messages: {
priceStr: {
required : "请填写价格"
}
}
});
input只可以输入数字或者是最多小数点2位的js代码
最新推荐文章于 2024-05-23 11:38:15 发布