如何自定义Jquery表单Validator方法和特定的高棉unicode

时间:2017-01-03 06:54:58

标签: javascript jquery validation formvalidation-plugin jquery-form-validator

我尝试使用jQuery表单Validator来验证用户在选择标识时是否不遵循设置规则,如果这些字符是Unicode,则会检查这些规则。 1,

  1. 如果条件等于F(家庭书) 我已在现有规则中添加新规则

    rules = {         最小长度:1,         最大长度:20,         要求:真     };

  2. 并将添加新方法来验证另一个规则,使用正则表达式库。来检测该输入值是否匹配高棉语Unicode 1780 - 17FF作为图像,但我找不到所有那些正则表达式现在。

    This is the images of those rules

    var regular_expressions ='';
    customizeMethods('#id_number',regular_expressions ,'All the value should follow the rules');
    

    $('#id_type')。on(' change',function(e){     "使用严格的&#34 ;;

    var id_number = $('#id_number');
    var rules = {};
    
    switch ($(this).val()) {
    
        case 'N': //Nationality
        rules = {
            minlength: 9,
            maxlength: 9,
            required:true,
            number: true
        };
             break;
        case 'F': //Family book
    
            rules = {
                minlength: 1,
                maxlength: 20,
                required:true
            };
            var regular_expressions ='';
            customizeMethods('#id_number',regular_expressions ,'All the value should follow the rules');
            break;
    
        case 'P'://Passpart
            rules = {
                minlength: 5,
                maxlength: 15,
                required:true
            };
            break;
        case 'D':///Driver
            rules = {
                minlength: 5,
                maxlength: 20,
                required:true
            };
    
            break;
        case 'G'://
            rules = {
                minlength: 1,
                maxlength: 20,
                required:true
            };
            break;
        case 'B':
    
            rules = {
                minlength: 1,
                maxlength: 20,
                required:true
            };
            break;
        case 'V':
    
            rules = {
                minlength: 1,
                maxlength: 20,
                required:true
            };
            break;
        case 'T':
    
            rules = {
                minlength: 1,
                maxlength: 20,
                required:true
            };
            break;
        case 'R':
    
            rules = {
                minlength: 1,
                maxlength: 20,
                required:true
            };
            break;
        default:
            break;
    }
    
    $('#id_number').rules( "add", rules);
    

    });

    自定义方法

    function customizeMethods(el,rules, sms ){
        "use strict";
    
        jQuery.validator.addMethod(el, function(value, element) {
            return this.optional(element) || rules.test( value );
        },sms);
    }
    

0 个答案:

没有答案