tgriesser / checkit

simple, flexible validations for node and the browser
MIT License
223 stars 53 forks source link

Contains - can I specify multiple values? #63

Open charlie-ablett opened 8 years ago

charlie-ablett commented 8 years ago

We're using an enum in the db to restrict a varchar field to a set of values (required or optional - which of course is confusing in itself! :-p)

Is this kind of validation possible?

necessity: [ 'required', { rule: 'contains', params: ['required', 'optional'] } ]

This only allows the first value... is this a bug or is this intentional? Is it possible to allow multiple valid values to be enumerated?

goowikns commented 8 years ago

+1 Would love to know too

dudeinthemirror commented 8 years ago

+1 please.

mzalazar commented 6 years ago

This is the code i use (some kind of "ENUM") for testing for 2 values, "final" and "test":

// Extend Checkit object
Checkit.Validator.prototype.types = function (val) {
    if (typeof val === 'string' && (val.toLowerCase() === 'test' || val.toLowerCase() === 'final')) {
        return true;
    } else {
        return false;
    }
}

USE:

new Checkit({
     my_param : ['types']
});