Giter VIP home page Giter VIP logo

validatorjs's Introduction

validatorjs

The validatorjs library makes data validation in JavaScript very easy in both the browser and Node.js. This library was inspired by the Laravel framework's Validator.

Why use validatorjs?

  • Works in both the browser and Node.
  • Readable and declarative validation rules.
  • Error messages with multilingual support.
  • CommonJS/Browserify support.
  • ES6 support.

Installation

Using npm

npm install validatorjs

Using yarn

yarn add validatorjs

Browser

<script src="validator.js"></script>

Node.js / Browserify

// ES5
let Validator = require('validatorjs');
// ES6
import * as Validator from 'validatorjs';

Basic Usage

let validation = new Validator(data, rules [, customErrorMessages]);

data {Object} - The data you want to validate

rules {Object} - Validation rules

customErrorMessages {Object} - Optional custom error messages to return

Example 1 - Passing Validation

let data = {
  name: 'John',
  email: '[email protected]',
  age: 28
};

let rules = {
  name: 'required',
  email: 'required|email',
  age: 'min:18'
};

let validation = new Validator(data, rules);

validation.passes(); // true
validation.fails(); // false

To apply validation rules to the data object, use the same object key names for the rules object.

Example 2 - Failing Validation

let validation = new Validator({
  name: 'D',
  email: 'not an email address.com'
}, {
  name: 'size:3',
  email: 'required|email'
});

validation.fails(); // true
validation.passes(); // false

// Error messages
validation.errors.first('email'); // 'The email format is invalid.'
validation.errors.get('email'); // returns an array of all email error messages

Nested Rules

Nested objects can also be validated. There are two ways to declare validation rules for nested objects. The first way is to declare the validation rules with a corresponding nested object structure that reflects the data. The second way is to declare validation rules with flattened key names. For example, to validate the following data:

let data = {
  name: 'John',
  bio: {
    age: 28,
    education: {
      primary: 'Elementary School',
      secondary: 'Secondary School'
    }
  }
};

We could declare our validation rules as follows:

let nested = {
  name: 'required',
  bio: {
    age: 'min:18',
    education: {
      primary: 'string',
      secondary: 'string'
    }
  }
};

// OR

let flattened = {
  'name': 'required',
  'bio.age': 'min:18',
  'bio.education.primary': 'string',
  'bio.education.secondary': 'string'
};

WildCards Rules

WildCards can also be validated.

let data = {
  users: [{
    name: 'John',
    bio: {
      age: 28,
      education: {
        primary: 'Elementary School',
        secondary: 'Secondary School'
      }
    }
  }]
};

We could declare our validation rules as follows:

let rules = {
  'users.*.name': 'required',
  'users.*.bio.age': 'min:18',
  'users.*.bio.education.primary': 'string',
  'users.*.bio.education.secondary': 'string'
};

Available Rules

Validation rules do not have an implicit 'required'. If a field is undefined or an empty string, it will pass validation. If you want a validation to fail for undefined or '', use the required rule.

accepted

The field under validation must be yes, on, 1 or true. This is useful for validating "Terms of Service" acceptance.

after:date

The field under validation must be after the given date.

after_or_equal:date

The field unter validation must be after or equal to the given field

alpha

The field under validation must be entirely alphabetic characters.

alpha_dash

The field under validation may have alpha-numeric characters, as well as dashes and underscores.

alpha_num

The field under validation must be entirely alpha-numeric characters.

array

The field under validation must be an array.

before:date

The field under validation must be before the given date.

before_or_equal:date

The field under validation must be before or equal to the given date.

between:min,max

The field under validation must have a size between the given min and max. Strings, numerics, and files are evaluated in the same fashion as the size rule.

boolean

The field under validation must be a boolean value of the form true, false, 0, 1, 'true', 'false', '0', '1',

confirmed

The field under validation must have a matching field of foo_confirmation. For example, if the field under validation is password, a matching password_confirmation field must be present in the input.

date

The field under validation must be a valid date format which is acceptable by Javascript's Date object.

digits:value

The field under validation must be numeric and must have an exact length of value.

digits_between:min,max

The field under validation must be numeric and must have length between given min and max.

different:attribute

The given field must be different than the field under validation.

email

The field under validation must be formatted as an e-mail address.

hex

The field under validation should be a hexadecimal format. Useful in combination with other rules, like hex|size:6 for hex color code validation.

in:foo,bar,...

The field under validation must be included in the given list of values. The field can be an array or string.

integer

The field under validation must have an integer value.

max:value

Validate that an attribute is no greater than a given size

Note: Maximum checks are inclusive.

min:value

Validate that an attribute is at least a given size.

Note: Minimum checks are inclusive.

not_in:foo,bar,...

The field under validation must not be included in the given list of values.

numeric

Validate that an attribute is numeric. The string representation of a number will pass.

present

The field under validation must be present in the input data but can be empty.

required

Checks if the length of the String representation of the value is >

required_if:anotherfield,value

The field under validation must be present and not empty if the anotherfield field is equal to any value.

required_unless:anotherfield,value

The field under validation must be present and not empty unless the anotherfield field is equal to any value.

required_with:foo,bar,...

The field under validation must be present and not empty only if any of the other specified fields are present.

required_with_all:foo,bar,...

The field under validation must be present and not empty only if all of the other specified fields are present.

required_without:foo,bar,...

The field under validation must be present and not empty only when any of the other specified fields are not present.

required_without_all:foo,bar,...

The field under validation must be present and not empty only when all of the other specified fields are not present.

same:attribute

The given field must match the field under validation.

size:value

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.

string

The field under validation must be a string.

url

Validate that an attribute has a valid URL format

regex:pattern

The field under validation must match the given regular expression.

Note: When using the regex pattern, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character. For each backward slash that you used in your regex pattern, you must escape each one with another backward slash.

Example 3 - Regex validation

let validation = new Validator({
  name: 'Doe',
  salary: '10,000.00',
  yearOfBirth: '1980'
}, {
  name: 'required|size:3',
  salary: ['required', 'regex:/^(?!0\\.00)\\d{1,3}(,\\d{3})*(\\.\\d\\d)?$/'],
  yearOfBirth: ['required', 'regex:/^(19|20)[\\d]{2,2}$/']
});

validation.fails(); // false
validation.passes(); // true

Example 4 - Type Checking Validation

let validation = new Validator({
  age: 30,
  name: ''
}, {
  age: ['required', { 'in': [29, 30] }],
  name: [{ required_if: ['age', 30] }]
});

validation.fails(); // true
validation.passes(); // false

Register Custom Validation Rules

Validator.register(name, callbackFn, errorMessage);

name {String} - The name of the rule.

callbackFn {Function} - Returns a boolean to represent a successful or failed validation.

errorMessage {String} - An optional string where you can specify a custom error message. :attribute inside errorMessage will be replaced with the attribute name.

Validator.register('telephone', function(value, requirement, attribute) { // requirement parameter defaults to null
  return value.match(/^\d{3}-\d{3}-\d{4}$/);
}, 'The :attribute phone number is not in the format XXX-XXX-XXXX.');

Asynchronous Validation

Register an asynchronous rule which accepts a passes callback:

Validator.registerAsync('username_available', function(username, attribute, req, passes) {
  // do your database/api checks here etc
  // then call the `passes` method where appropriate:
  passes(); // if username is available
  passes(false, 'Username has already been taken.'); // if username is not available
});

Then call your validator using checkAsync passing fails and passes callbacks like so:

let validator = new Validator({
	username: 'test123'
}, {
	username: 'required|min:3|username_available'
});

function passes() {
  // Validation passed
}

function fails() {
  validator.errors.first('username');
}

validator.checkAsync(passes, fails);

Error Messages

This constructor will automatically generate error messages for validation rules that failed.

If there are errors, the Validator instance will have its errors property object populated with the error messages for all failing attributes. The methods and properties on the errors property object are:

.first(attribute)

returns the first error message for an attribute, false otherwise

.get(attribute)

returns an array of error messages for an attribute, or an empty array if there are no errors

.all()

returns an object containing all error messages for all failing attributes

.has(attribute)

returns true if error messages exist for an attribute, false otherwise

.errorCount

the number of validation errors

let validation = new Validator(input, rules);
validation.errors.first('email'); // returns first error message for email attribute
validator.errors.get('email'); // returns an array of error messages for the email attribute

Custom Error Messages

If you need a specific error message and you don't want to override the default one, you can pass an override as the third argument to the Validator object, just like with Laravel.

let input = {
  name: ''
};

let rules = {
  name : 'required'
};

let validation = new Validator(input, rules, { required: 'You forgot to give a :attribute' });
validation.passes();
validation.errors.first('name'); // returns 'You forgot to give a name'

Some of the validators have string and numeric versions. You can change them too.

let input = {
  username: 'myusernameistoolong'
};

let rules = {
  username : 'max:16'
};

let validation = new Validator(input, rules, {
  max: {
    string: 'The :attribute is too long. Max length is :max.'
  }
});
validation.passes();
validation.errors.first('username'); // returns 'The username is too long. Max length is 16.'

You can even provide error messages on a per attribute basis! Just set the message's key to 'validator.attribute'

let input = { name: '', email: '' };
let rules = { name : 'required', email : 'required' };

let validation = new Validator(input, rules, {
  "required.email": "Without an :attribute we can't reach you!"
});

validation.passes();
validation.errors.first('name'); // returns  'The name field is required.'
validation.errors.first('email'); // returns 'Without an email we can\'t reach you!'

Custom Attribute Names

To display a custom "friendly" attribute name in error messages, use .setAttributeNames()

let validator = new Validator({ name: '' }, { name: 'required' });
validator.setAttributeNames({ name: 'custom_name' });
if (validator.fails()) {
  validator.errors.first('name'); // "The custom_name field is required."
}

Alternatively you can supply global custom attribute names in your lang with the attributes property.

You can also configure a custom attribute formatter:

// Configure global formatter.
Validator.setAttributeFormatter(function(attribute) {
  return attribute.replace(/_/g, ' ');
});

// Or configure formatter for particular instance.
let validator = new Validator({ first_name: '' }, { first_name: 'required' });
validator.setAttributeFormatter(function(attribute) {
  return attribute.replace(/_/g, ' ');
});
if (validator.fails()) {
  console.log(validator.errors.first('first_name')); // The first name field is required.
}

Note: by default all _ characters will be replaced with spaces.

Language Support

Error messages are in English by default. To include another language in the browser, reference the language file in a script tag and call Validator.useLang('lang_code').

<script src="dist/validator.js"></script>
<script src="dist/lang/ru.js"></script>
<script>
  Validator.useLang('es');
</script>

In Node, it will automatically pickup on the language source files.

let Validator = require('validatorjs');
Validator.useLang('ru');

If you don't see support for your language, please add one to src/lang!

You can also add your own custom language by calling setMessages:

Validator.setMessages('lang_code', {
  required: 'The :attribute field is required.'
});

Get the raw object of messages for the given language:

Validator.getMessages('lang_code');

Switch the default language used by the validator:

Validator.useLang('lang_code');

Get the default language being used:

Validator.getDefaultLang(); // returns e.g. 'en'

Override default messages for language:

let messages = Validator.getMessages('en');
messages.required = 'Whoops, :attribute field is required.';
Validator.setMessages('en', messages);

License

Copyright ยฉ 2012-2019 David Tang Released under the MIT license

Credits

validatorjs created by David Tang validatorjs maintained by Mike Erickson and Contributors

E-Mail: [email protected]

Twitter: @codedungeon

Website: codedungeon.io

validatorjs's People

Contributors

afitiskin avatar alanhr avatar almis90 avatar ameensom avatar bezi avatar davichaves avatar estebanprimost avatar eugen-sebp avatar garygreen avatar hassankhan avatar hillerstorm avatar imangazaliev avatar jartaud avatar jgallred avatar kaareloun avatar lkay avatar lorenzodalaqua avatar maidanskyi avatar mfour-merickson avatar mgibas avatar mikeerickson avatar richriscunha avatar roxannedunn avatar sdr0x07b6 avatar simondegraeve avatar ts95 avatar vict-shevchenko avatar vir2bille avatar yangmillstheory avatar zamarawka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

validatorjs's Issues

fails() is true when processing a rule without matching input value

Hi,

Today I noticed that while validating a rule without a matching input value it is possible to get a fail state. At the moment, in my situation, it would be preferable to have the validation pass in such a situation. However, Im not really sure of why a validation should fail if a rule exists, but not the matching input value. It seems like it should be possible to have a rules list that contains validations that should not be executed for every validation. For instance if I have a common validation json that I want to be used for the entire project.

Please let me know if Im thinking in the wrong direction.

[Idea] Success messages

It could be quite useful to have 'success messages' where you want to display feedback to the user about each rule (or maybe just one overall success message).

For instance, if your building a form that outputs a list of errors for a field, you could also (as you start typing) check in real time which rules are passing:

  • Username is more than 5 characters โœ“
  • Username is not taken โœ“

Ideally don't want to overcomplicate validatorjs but I think there is some value in this feature.

Trigger on change validation

HI,

Let say i have form to validate, how to validate it when trigger on change action without duplicate the code.
Now when click on submit button, can validate all together.
For sample below, how to just validate email or name when trigger on change. it is possible to do without duplicate the rules one by one?

Sample:
var data = {
name: 'John',
email: '[email protected]',
age: 28
};

var rules = {
name: 'required',
email: 'required|email',
age: 'min:18'
};

var validation = new Validator(data, rules);

Return different from laravel

In laravel when I create rule

'name'=> 'min:4|max:22|required'

and I just fill the name input with space it's return "The name field is required."

In validatorjs when I create rule

{name:'min:6|max:20|required'}

then I fill the name input with space it's return

{ name:
   [
      'The name must be at least 6 characters.',
      'The name field is required.'
   ] 
}

I think the first error should be "the name field is required", isn't?

Add custom validation rule

Any docs on how to do this? Is it just Validator.prototype.validate.my_custom_rule = function() { ... } ?

Would be cool to be able to do like in Laravel:

Validator.extend('my_custom_rule', ...);

Override default messages

Although you can customise the error messages on a per-field basis, it can be quite tedious if you want to always have a different message.

Would be cool to be able to do something like the below (of course still having ability to override with customMessages).

Validator.setMessages({
   required: 'This field is required'
});

Problem with titanium appcelerator

Hi! I've some problems with implements the library in Titanium Appcelerator, the application close when I require the resource, I hope help me fixing this issue.

regards :)

Numeric based validation rules issue

At the moment the validator does a basic type-check to see if it should compare the length or actual value.

For example, this should validate that the person is a min of 18 years old, but because it's a string of 20 it's validated against it's character length, even though the 'integer' rule is there.

var v = new Validator({ age: '20' }, { age: 'required|integer|min:18' });
if (v.fails())
{
    console.log('error', v.errors); // The age must be at least 18 characters.
}

Laravel handles this by a getSize method and checking if there is numeric-based rules, if so compares it as such, if not then compares it's length. This is how it also supports arrays etc.

i18n

Hello,
Would it be possible to include error messages as an external file or wrap them in an object so we can translate the messages globally and easily swap between langages ?

TypeError: passes is not a function

I just found you're awesome JS Laravel validator! Nice work, was thinking about building one similar till i found this.

I am using this within AngularJS.

When i run this with errors in the form, the error cb is called fine (note there is no passes). However if I run this when the form passes the validators i get an error: "TypeError: passes is not a function" which is expected:

var validation = new Validator( dataToValidate, validationRules );
validation.fails(function(){
      Toolbox.metaFromFlatObject( $scope.stockTypeMeta, validation.errors.all(), 'error' );
});

Now, when i add the passes cb I get unexpected results.
Failing the form results in the fails cd being run but also an error in the console: "TypeError: fails is not a function"
Passing the form results in "TypeError: passes is not a function" but the cb is not called.

var validation = new Validator( dataToValidate, validationRules );
validation.fails(function(){
     Toolbox.metaFromFlatObject( $scope.stockTypeMeta, validation.errors.all(), 'error' );
});
validation.passes(function(){
     alert('passed!' );
});

If i chain the passes directly after the initialiser I can get the passes cb to run, however immediately after it has run i get an error "TypeError: Cannot read property 'fails' of undefined":

var validation = new Validator( dataToValidate, validationRules).passes(function(){
   alert('passed!' );
});

validation.fails(function(){
    Toolbox.metaFromFlatObject( $scope.stockTypeMeta, validation.errors.all(), 'error' );
});

Chaining the fails onto the end results in "TypeError: fails is not a function"

How can I get this working?

the validation rules should not imply required

currently if you specify a rule like 'email', then that also implies required. but what if you want a field to be optional and if entered, it should be in the format of an email address.

Add ability to set custom attribute names

I know this validator js inspired on Laravel's one and not a direct clone, but in Laravel's validator you can customise the attribute names that are shown in the error messages. So if you validating an attribute named friends.3.notes you can override the name to appear as simply notes.

Something like the below would be cool:

var validator = new Validator({ 'friends.1.notes': '' }, { 'friends.1.notes': 'required' });
validator.setCustomAttributes({
    'friends.1.notes': 'notes'
});
if (validator.fails())
{
    validator.errors.first(); // Will output: 'notes is required.'
}

Refactor rule parameters

At the moment rules receive 3 different parameters like:

size: function(val, req, attribute) {

With the async rules this would become more complex like:

size: function(val, req, attribute, passes) {

Maybe this can be refactored for all rules to simply accept a TestRule object, and it can act upon that. For instance:

size: function(testRule) {
    testRule.value; // Value being tested
    testRule.attribute; // Attribute being tested
    testRule.getSize(); // Get the 'true' size of the value
    testRule.getParameters(); // Rule parameter, e.g. for 'size:3' would return 3
    testRule.isAsync(); // If the rule is being tested asynchronously
    testRule.passes(); // When async is supported
    testRule.passes(false); // When async is supported
    testRule.passes(false, 'Custom error message'); // When async is supported
    this.validateRule('min:3', testRule.value); // Idea for testing against another rule
}

[Proposal] Bower Distribution

Just started working with this package for client side validations for one of our projects at work.

I know that a lot of users are starting to move to Bower for their client-side asset management.

I am willing to help out to get this package listed on Bower and to create a bower.json file that will just ship the dist folder. Let me know if this is something you would be interested in and I can work up a quick PR for this.

Requiring unknown module "./lang/en"

I'm trying to use this package in react-native, but unfortunately requiring the module results in the following error:

Requiring unknown module "./lang/en". If you are sure the module is there, try restarting the packager.

Is this something specific to the fact that I'm using react-native, or am I making a rookie mistake here? Any input would be appreciated.

Attributes named has, get, first

Due to the way in which the validator errors class stores the errors, if you have attributes named has get or first with errors, it will override the functions on that class. I can see why it's been done that way, because it makes it easier to access the errors by .errors.first_name

var validator = new Validator({ has: '' }, { has: 'required' });
if (validator.fails()) {
    console.log(validator.errors.has('test')); // 'has' is not a function
}

Maybe it should store the errors on a new object, and you can still access the raw errors by .all()

Validator.errors.all().first_name

Add attribute formatter

If your validating a field named last_name the error message will come back as:

The last_name field is required.

This formatting is a bit unsightly, it would be cool to add a generic attribute formatter that will remove some characters to make it more readable. By default it will remove some sane characters like _- but can be overridden like:

Validator.setAttributeFormatter(function(attribute) {
    return attribute.replace(/[_]/g, ' ');
});

License Required

To be used by other developers, this project needs a license.

Cheers.

Don't validate as soon as instantiated

At the moment validation is run as soon as the instance is created. This makes it diffiuclt to act on the validation object and change defaults, etc before you actually go to validate. I was kind of suprised by this behavior actually, as I assumed it would validate only once you did passes or fails

Maybe this can be changed? That way you can implement something like the below (which is my idea for PR #40):

var validator = new Validator({ 'users[0][full_name]': ''}, { 'users[0][full_name]': 'required' });
validator.setCustomAttributes({ 'users[0][full_name]': 'Full Name' });
validator.passes();

"npm install validatejs" installs something very different..

I am sort of new to nodejs.. I tried installing this package both global and local and none of them work. So I ended up copying the js file in your /dist folder in github and require it to get it work. But that way I cant get the new commits from you guys.
Whats the problem with npm?

By the way I specifically put the keywords on google as "laravel like nodejs validation". You guys came up! awesome job!

Asynchronous validation

Currently this library only supports synchronous validation. The nature of javascript is pretty asynchronous so it's definitely a worthwhile feature to have.

For instance, you could have a username_available validation rule which performs an ajax check for availability of the username.

I'm not sure what architectural changes would be needed for this, but I think possibly just a case of adding some functions passesAsync() failsAsync() which returns a promise, along with promise support when calling the actual validators? Or maybe change the validator so it supports async by default (would be breaking change but would simplify and be a single-entry point for validation logic).

validator.passes(function() {
 // Yipee!
});

validator.fails(function(errors) {
 // Waa
});

Support arrays with "in" rule

At the moment the in rule forces the value to a string. I would expect it to rule true for the below.

var validator = new Validator({ fruits: ['apple', 'strawberry'], { fruits: 'array|in:apple,strawberry' });
validator.passes(); // Should be true.

Laravel supports this as well (assuming there is also an array rule for the attribute)

Language loading clarification

Hey,
Maybe I'm looking at this the wrong way, but in order to get a browserify setup to load a language file, I had to move the langs function from validator.js to _lang.js. Otherwise a module not found would be reported for ./lang/code.
Any thoughts on this?
Thanks!

Introducing dominar.js

Not strictly an 'issue' but thought I'd share with you a library I've built on-top of this brilliant validator.js.

https://github.com/garygreen/dominar

It's in very early prototype stages so lots of work still to do (namely support elements like selects, checkboxes, radios etc) but that shouldn't be too difficult.

Main reason for building it is I absolutely love this library and would love to use it for form validation, as it's syntax is very expressive and easy to use (also adds the possibility of simply sharing your Laravel validation rules from server to client pretty easily). Bootstrap offers a very nice way to show error messages and is generally what I use for most of my front-end projects.

Dominar is extremely expressive and easily configurable (and fast!) straight out of the box. You don't have to edit your markup at all to get it working (all that's needed is your element under validation to be wrapped inside a .form-group).

Oh, and it's only 3.5KB gzipped (with validator.js). There isn't another validator out there that is that small with so many features.

It is in the early stages but I would much appreciate if you could share your thoughts on it (coding style, usage of validator.js, etc). Once it becomes more stable I would be very grateful if you would consider linking to it from the validator.js readme. ๐Ÿ˜„

Validator.js 2.0

I think it would be a good idea to move towards a goal of version 2.0. I know there's a big thing about backwards compatibility, but it's pretty stable at the moment so let's work towards a major release knowing we can change a few things without being overly concerned with backwards compatibility etc. In any case, the upgrade path will be very straight forward.

So for version 2.0:

  • Asynchronous validation #37
  • Improve restructuring of library by using browserify issue #45
  • Run tests on node and browser, switch to mocha
  • Ability to override default messages issue #41
  • Improve language support by not requiring custom validator builds and easy switching of language PR #42
  • Change to not validating as soon as instantiated issue #44
  • Array validation rule
  • Fixed to allow unsigned values on integer rule
  • Ability to format attributes issue #54
  • Add 'required_*' conditional rules issue #57
  • Docblock entire codebase
  • Readme
  • Change log / Upgrade guide

new Validator

ReferenceError: messages is not defined
at new Validator (/Users/Miguel/proyectosNodejs/gestionA/node_modules/validatorjs/src/validator.js:4:32)

only created a simple rule and simple data using your example

Add stopOnError

As soon as first error occurred, stop testing other other validation rules.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.