1

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

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

    规则 = { minlength: 1, maxlength: 20, required:true };

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

这是那些规则的图像

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

$('#id_type').on('change', function(e) { "use strict";

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);
}
4

0 回答 0