1. 程式人生 > >EasyUI驗證form表單

EasyUI驗證form表單

missingMessage="必輸項提示" data-options="required:true" validType="email" invalidMessage="自定義提示語" (只能使用官方定義好的驗證)


自定義驗證:

$(function(){ 
  $.extend($.fn.validatebox.defaults.rules, {
      english : {// 驗證英語
                  validator : function(value){
                   return /^[A-Za-z]+$/i.test(value);
                  },
                  message : '請輸入英文'
              }
  }
});

(function($) {  
    $.extend($.fn.validatebox.defaults.rules, {  
        idcard: {  
            validator: function(value, param) {  
                return idCardNoUtil.checkIdCardNo(value);  
            },  
            message: '請輸入正確的身份證號碼'  
        },  
        checkNum: {  
            validator: function(value, param) {  
                return /^([0-9]+)$/.test(value);  
            },  
            message: '請輸入整數'  
        },  
        checkFloat: {  
            validator: function(value, param) {  
                return /^[+|-]?([0-9]+\.[0-9]+)|[0-9]+$/.test(value);  
            },  
            message: '請輸入合法數字'  
        }  
    });  
})(jQuery);
2種用法差不多,只是初始化jq的程式碼方式不一樣而已
<input class="easyui-validatebox" data-options="validType:'english'"> 

<input type="text" name="dlg_purchase_price" id="dlg_purchase_price"  <span style="color:#ff0000;">class="easyui-validatebox" data-options="validType:'checkFloat'"</span> />  


//阻止form表單提交 必須驗證完畢才可提交
	                    if(!$("#fm_dg").form('validate')){
	                    	return false;
	                    	}
寫在 提交前即可