Socket
Socket
Sign inDemoInstall

modella-validators

Package Overview
Dependencies
4
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    modella-validators

Validators for Modella


Version published
Maintainers
2
Install size
92.7 kB
Created

Readme

Source

Modella Validators

Build Status

A plugin that provides a bunch of validators for modella.

Example Usage

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

Basic Validators

Required

Verifies that a field is present.

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

Confirms

Verifies that a field equals another field.

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

Type

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 });

Choices

Checks that a field is one of the specified choices

var User = User.attr('state', {choices: ['CONFIRMED', 'PENDING']})

Format Validators

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

Format

Validates the field against the given regular expression

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

Phone Number

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

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

Email Address

Validates the field against a email address format

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

URL

Validates the field against a URL format

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

Keywords

FAQs

Last updated on 28 Jun 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc