当前位置:编程学习 > JS >>

esui控件validatebox 通过正则判断输入 json传值

 
<pre name="code" class="html"></pre><pre name="code" class="html"><td>  
            @Html.TextBoxFor(m => m.ActualInvoiceFee, new  
               {  
                   @id = "txtActualInvoiceFee",  
                   @style = "width:80px",  
                   @class = "easyui-validatebox",  
                   @validType = @"VerifyMoney[{'maxVal':999999 ,'minVal':-999999},'只能输入数字']",  
                   @required = "true",  
                   @missingMessage = "必须填写发票金额"  
               })  
</td></pre>  
 

 
//add by gongth验证金额  
    $.extend($.fn.validatebox.defaults.rules, {  
        VerifyMoney: {  
            validator: function (value, param) {  
                var reg = /^(|[+-]?(0|([1-9]\d*)|((0|([1-9]\d*))?\.\d{1,2})){1,1})$/;  
                value = value.Trim();  
                if (reg.test(value)) {  
                    var maxVal = param[0]['maxVal'];  
                    var minVal = param[0]['minVal'];  
                    if (maxVal != null) {  
                        if (reg.test(maxVal)) {  
                            if (value > maxVal) {           
                                $.fn.validatebox.defaults.rules.VerifyMoney.message = "超出范围";  
                                return false;  
                            }  
                        }  
                    }  
                    if (minVal != null) {  
                        if (reg.test(minVal)) {  
                            if (value < minVal) {             
                                $.fn.validatebox.defaults.rules.VerifyMoney.message = "超出范围";  
                                return false;  
                            }  
                        }  
                    }  
                    return true;  
                } else {  
                    $.fn.validatebox.defaults.rules.VerifyMoney.message = param[1];  
                    return false;  
                }  
            },  
            message: ''  
        }  

 

 
补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,