Modules (188)

ValidationUtils

Description

Dependencies

This module has no dependencies

Functions

Public API

isInteger

Used to validate whether type of unknown value is an integer.

value *
Value for which to validate its type
Returns: boolean
true if value is a finite integer
    function isInteger(value) {
        // Validate value is a number
        if (typeof (value) !== "number" || isNaN(parseInt(value, 10))) {
            return false;
        }

        // Validate number is an integer
        if (Math.floor(value) !== value) {
            return false;
        }

        // Validate number is finite
        if (!isFinite(value)) {
            return false;
        }

        return true;
    }
Public API

isIntegerInRange

Used to validate whether type of unknown value is an integer, and, if so, is it within the option lower and upper limits.

value *
Value for which to validate its type
lowerLimit optional number
Optional lower limit (inclusive)
upperLimit optional number
Optional upper limit (inclusive)
Returns: boolean
true if value is an interger, and optionally in specified range.
    function isIntegerInRange(value, lowerLimit, upperLimit) {
        // Validate value is an integer
        if (!isInteger(value)) {
            return false;
        }

        // Validate integer is in range
        var hasLowerLimt = (typeof (lowerLimit) === "number"),
            hasUpperLimt = (typeof (upperLimit) === "number");

        return ((!hasLowerLimt || value >= lowerLimit) && (!hasUpperLimt || value <= upperLimit));
    }


    // Define public API
    exports.isInteger               = isInteger;
    exports.isIntegerInRange        = isIntegerInRange;
});