Validate String length - Node.js Date

Node.js examples for Date:Date Format

Description

Validate String length

Demo Code

Validator.validateLength = function(str, min, max) {
    if (min === 0 && max === 0) {
        throw "Validator : When calling validateLength min or max should be different from 0.";
    }/*  www . j a  v a 2 s  .  c o m*/
    if ((min >= max || max <= min) && (max !== 0)) {
        throw "Validator : When calling validateLength min is the minimum and max should be the maximum.";
    }
    if (min !== 0 && max !== 0) {
        if (str.length > min && str.length < max) {
            return true;
        } else {
            return false;
        }
        return false;
    }
    if (min === 0 && max !== 0) {
        if (str.length < max) {
            return true;
        } else {
            return false;
        }
        return false;
    }
    if (min !== 0 && max === 0) {
        if (str.length > min) {
            return true;
        } else {
            return false;
        }
        return false;
    }
    return false;
};

Related Tutorials