const Validation = (function() {
    'use strict';

    const forms = {};
    const error_class  = 'error-msg';
    const hidden_class = 'hidden';

    const events_map = {
        input   : 'input change',
        select  : 'change',
        checkbox: 'change',
    };

    const getFieldType = ($field) => {
        if (!$field.length) return null;
        let type = $field.get(0).localName;
        if (type === 'input' && $field.attr('type') === 'checkbox') {
            type = 'checkbox';
        }
        return type;
    };

    const getFieldValue = $field => (getFieldType($field) === 'checkbox' ? ($field.is(':checked') ? '1' : '') : $field.val()) || '';

    const initForm = (form_selector, fields) => {
        const $form = $(`${form_selector}:visible`);
        if ($form.length && Array.isArray(fields) && fields.length) {
            forms[form_selector] = { fields: fields, $form: $form };
            fields.forEach((field) => {
                field.$ = $form.find(field.selector);
                if (!field.$.length) return;

                field.form = form_selector;
                if (field.msg_element) {
                    field.$error = $form.find(field.msg_element);
                } else {
                    const $parent = field.$.parent();
                    if ($parent.find(`div.${error_class}`).length === 0) {
                        $parent.append($('<div/>', { class: `${error_class} ${hidden_class}` }));
                    }
                    field.$error = $parent.find(`.${error_class}`);
                }

                const event = events_map[getFieldType(field.$)];
                if (event) {
                    field.$.unbind(event).on(event, () => {
                        checkField(field);
                    });
                }
            });
        }
    };

    // ------------------------------
    // ----- Validation Methods -----
    // ------------------------------
    const validRequired = value => value.length;
    const validEmail    = value => /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$/.test(value);
    const validPassword = value => /(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]+/.test(value);
    const validGeneral  = value => !/[`~!@#$%^&*)(_=+\[}{\]\\\/";:\?><,|\d]+/.test(value);
    const validPostCode = value => /^[a-zA-Z\d-]*$/.test(value);
    const validPhone    = value => /^\+?[0-9\s]*$/.test(value);

    const validCompare = (value, options) => value === $(options.to).val();
    const validMin     = (value, options) => (options.min ? value.trim().length >= options.min : true);
    const validLength  = (value, options) => (
        (options.min ? value.trim().length >= options.min : true) &&
        (options.max ? value.trim().length <= options.max : true)
    );

    const validators_map = {
        req     : { func: validRequired,  message: 'This field is required' },
        email   : { func: validEmail,     message: 'Invalid email address' },
        password: { func: validPassword,  message: 'Password should have lower and uppercase letters with numbers.' },
        general : { func: validGeneral,   message: 'Only letters, space, hyphen, period, apost are allowed.' },
        postcode: { func: validPostCode,  message: 'Only letters, numbers, hyphen are allowed.' },
        phone   : { func: validPhone,     message: 'Only numbers, space are allowed.' },
        compare : { func: validCompare,   message: 'The two passwords that you entered do not match.' },
        min     : { func: validMin,       message: 'Minimum of [_1] characters required.' },
        length  : { func: validLength,    message: 'You should enter [_1] characters.' },
    };

    const pass_length = { min: 6, max: 25 };

    // --------------------
    // ----- Validate -----
    // --------------------
    const checkField = (field) => {
        let all_is_ok = true,
            message;

        field.validations.some((valid) => {
            let type,
                options = {};

            if (typeof valid === 'string') {
                type = valid;
            } else {
                type    = valid[0];
                options = valid[1];
            }

            if (type === 'password' && !validLength(getFieldValue(field.$), pass_length)) {
                field.is_ok = false;
                type = 'length';
                options = pass_length;
            } else {
                const validator = validators_map[type].func;
                field.is_ok = validator(getFieldValue(field.$), options, field.form);
            }

            if (!field.is_ok) {
                message = options.message || validators_map[type].message;
                if (type === 'length') {
                    message = message.replace('[_1]', options.min === options.max ? options.min : `${options.min}-${options.max}`);
                } else if (type === 'min') {
                    message = message.replace('[_1]', options.min);
                }
                all_is_ok = false;
                return true;
            }
            return false;
        });

        if (!all_is_ok) {
            showError(field, message);
        } else {
            clearError(field);
        }

        return all_is_ok;
    };

    const clearError = (field) => {
        if (field.$error && field.$error.length) {
            field.$error.addClass(hidden_class);
        }
    };

    const showError = (field, message) => {
        clearError(field);
        field.$error.text(message).removeClass(hidden_class);
    };

    const validate = (form_selector) => {
        const form = forms[form_selector];
        form.is_ok = true;
        form.fields.forEach((field) => {
            if (!checkField(field)) {
                if (form.is_ok) { // first error
                    $.scrollTo(field.$, 500, { offset: -10 });
                }
                form.is_ok = false;
            }
        });
        return form.is_ok;
    };

    return {
        init    : initForm,
        validate: validate,
    };
})();

module.exports = Validation;

@@ -293,21 +293,19 @@
 e = 
-(
 $field
-)
  =%3E 
-%7B
+(
 %0A   
@@ -309,21 +309,16 @@
         
-if (!
 $field.l
@@ -326,204 +326,99 @@
 ngth
-) return null;%0A        let type = $field.get(0).localName;%0A        if (type === 'input' && $field.attr('type') === 'checkbox') %7B%0A            type = 'checkbox';%0A        %7D%0A        return type;
+ ? ($field.attr('type') === 'checkbox' ? 'checkbox' : $field.get(0).localName) : null
 %0A    
-%7D
+)
 ;%0A%0A 

Optimize the code