how to customize Jquery form Validator method and and a specific khmer unicode

163 views Asked by At

I'm trying to use jQuery form Validator to validate if users don't follow the setting rules when identification was selected and those rules will be checked if those character is Unicode or not. 1,

  1. If the conditional equal to F (Family book) I've add new rules to existing rules

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

And will add new method to validate another rules by using library of regular expressions. to detecting if that input value matching Khmer Unicode 1780 – 17FF as the image but I can not find all those regular expressions now.

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) { "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);

});

Customization method

function customizeMethods(el,rules, sms ){
    "use strict";

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

There are 0 answers