Using Easyui to do business system, for the default of a few validation rules, is certainly not enough, inevitably will add several rules. But the problem comes, often we encounter a lot of various validation in the development, long time to discover that these extensions are just adding a regular validation rule, then why don't I put the regular to the front? Think of this say dry, so have a regex this validation rule, happy call several times, feel this function is good, in the mind thief cool. After some time, found that some of the verification is still related to the data business, the question comes again, I will have a bunch of rules! Can it be as uniform as my regular validation? Sure enough, after a half an hour of pondering, my fun validation rules surfaced.
Custom Regular Validation regex: { validator:function (value, param) { var REGEX = param[0]; var re = new RegExp (regex); return re.test (value); }, message: ' {1} ' }, //Custom Function Validation fun : { validator:function (value, param) { var fun = param[0]; if ($.isfunction) { return fun (value); } return true; }, message: ' {1} ' },
Explain, $.extend ($.fn.validatebox.defaults.rules,{}), here can extend a lot of rules, of course, now the REGEX and fun rules, feel can not write other rules, little satisfaction.
Wow, the function is so powerful, how do I use it?
Fun:
<label for= "F_FPSL" class= "input_lable" > Invoice tax rate (%) </label><input type= "text" name= "F_FPSL" class= " Easyui-textbox input_box "data-options=" width:107,prompt: ' multiple tax rates comma separated ', VALIDTYPE:{FUN:[JSDWXX.VALIDATAFPSL, ' Invoice tax rate can only be entered into the number ']} "/>
Regex:
<label for= "F_SBDQ" class= "input_lable" > Escalation area </label><input type= "text" name= "F_SBDQ" class= " Easyui-textbox input_box "data-options=" width:132,prompt: ' For example: ZYCC ', validtype:{regex:[' ^[a-za-z]{4}$ ', ' reporting area of 4 letters ' ]},BOXCLS: ' Uppercase ' "/></li>
PS: Rule {0},{1},{...} and front definition regex:[0,1,...] One by one correspondence
Easyui extended Regular validation, function validation