Skip to content

MokoJs/validators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moko Validators

A plugin that provides a bunch of validators for moko.

Example Usage

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

Basic Validators

Required

Verifies that a field is present.

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

Confirms

Verifies that a field equals another field.

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

Type

Checks that a field is of a given type

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

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

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

// Or

User.attr('name', { type: String });

Format Validators

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

Format

Validates the field against the given regular expression

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

Phone Number

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

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

Email Address

Validates the field against a email address format

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

URL

Validates the field against a URL format

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

Credit Card

Validates the field against a credit card format.

User.attr('cc', {format: 'creditcard' });

About

Validators for Moko

Resources

Stars

Watchers

Forks

Packages

No packages published