Simple JavaScript validation object for validating various types

Wed, 17 January 2018

rlib_validator.js
var rlib_validator = {
    email: function(x) {
        return (/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,63})+$/.test(x));
    },
    password: function(x, min_length, max_length, req_uppercase, req_lowercase, req_number) {
        min_length = min_length || 8;
        max_length = max_length || 999;
        req_uppercase = req_uppercase || false;
        req_lowercase = req_lowercase || false;
        req_number = req_number || false;
        if (x.indexOf(' ') !== -1) {
            return false;
        }
        if (req_uppercase === true) {
            var upper=/^(?=.*[A-Z])/;
            if (upper.test(x) == false) {
                return false;
            }
        }
        if (req_lowercase === true) {
            var lower=/^(?=.*[a-z])/;
            if (lower.test(x) == false) {
                return false;
            }
        }
        if (req_number === true) {
            var number=/^(?=.*[0-9])/;
            if (number.test(x) == false) {
                return false;
            }
        }
        return (x.length >= min_length && x.length <= max_length)
    },
    datastoreId: function(x) {
        if (this.integer(x) === false) {
            return false;
        }
        return (String(x).length === 16)
    },
    integer: function(x){
        return (isNaN(parseInt(x)) === false);
    },
    integerRange: function(x, min, max){
        if (this.integer(x) === false) {
            return false;
        }
        if (parseInt(x) < min || parseInt(x) > max) {
            return false;
        }
        return true;
    }
};