Easyui extended Regular validation, function validation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.