Validators for Modella

Model Validators

A plugin that provides a bunch of validators for modella.

var Person = modella('Person').attr('name', { required: true }),
    validation = require('modella-validators');

Verifies that a field is present.

var User = User.attr('username', {required: true});

Verifies that a field equals another field.

var User = User.attr('password')
               .attr('passwordConfirmation', { confirms: 'password' });

Checks that a field is of a given type

var User = User.attr('name', {type: 'string'});

In addition to string support for primitives, you can also pass in a constructor.

var User = User.attr('parent', { type: User });

Verify the value of a field against a regex pattern. modella-validators comes with a few regex strings built in under the formatStrings object.

Validates the field against the given regular expression

var User = User.attr('name', {format: /\w+ \w+/ });

Validates the field against a (North American) phone number format

var User = User.attr('phone', {format: 'phone' });

Validates the field against a email address format

var User = User.attr('email', {format: 'email' });

Validates the field against a URL format

var User = User.attr('website', {format: 'url' });