poppinss / indicative

Indicative is a simple yet powerful data validator for Node.js and browsers. It makes it so simple to write async validations on nested set of data.
https://indicative.adonisjs.com/
MIT License
417 stars 52 forks source link

Min/Max for numeric/files #221

Closed padinko closed 5 years ago

padinko commented 5 years ago

Min and Max validators should compare numeric values when value is numeric, or file size when value is file. Laravel documentation:

The field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to a given integer value. For an array, size corresponds to the count of the array. For files, size corresponds to the file size in kilobytes.

Package version

5.0.8

Node.js and npm version

node 10.15.3 npm 6.9.0

Sample Code (to reproduce the issue)

class Offset {
    get validateAll() {
        return true;
    }

    get sanitizationRules() {
        return {
            offset: 'to_int',
        };
    }

    get rules() {
        return {
            offset: 'integer|min:1',
        };
    }
}

module.exports = Offset;

This example on data { offset: 0 } returns OK, but zero is below min value. Maybe this validators should check previous validators and then decide which type to use.

thetutlage commented 5 years ago

Sorry for the late reply. What you are really looking for is the above rule