validatorjs icon indicating copy to clipboard operation
validatorjs copied to clipboard

Min rule is broken for empty strings

Open vladshcherbin opened this issue 7 years ago • 0 comments

min rule is working wrong for empty strings. Here is an example:

import Validator from 'validatorjs'

const data = {
  name: '',
  surname: ''
}

const rules = {
  name: 'required',
  surname: 'min:2'
}

const validation = new Validator(data, rules)

if (validation.fails()) {
  console.log(validation.errors.all())
}

Errors are:

{ name: [ 'The name field is required.' ] }

However, surname is an empty string and min:2 rule didn't return error.

Tested with [email protected]

vladshcherbin avatar Feb 09 '18 13:02 vladshcherbin