0.0.10 • Published 6 years ago

validate-str v0.0.10

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

validate string

validate string by regexp or function, return error message list.

usage

  validate([{
    name: 'id1',
    value: '123456789012345',
    validators: [
      {
        msg: 'please input',
        method: 'require'
      },
      {
        msg: 'identity error',
        method: 'identity'
      }
    ]
  },
  {
    name: 'id2',
    value: '123456789012345',
    validators: [
      {
        msg: 'please input',
        method: 'require'
      },
      {
        msg: 'identity error',
        method: 'identity'
      }
    ]
  }], {mode: 'single'})

params

validate(vlEntries, options)

  • vlEntries An array of validation
  • options options

vlEntries

see above example

vlEntries[].name

validation name, used by result list

vlEntries[].value

string to be validated

vlEntries[].validators

validator list

vlEntries[].validators[].msg

the message to be returned when validation fail

vlEntries[].validators[].method

the validate method, can be function, regexp, string

internal support method

supported regexp inner, you can use these regexp names as method directly.

options

options.mode

single

only return the first error object when validation fails.

  {
    name: 'id1',
    errors: ['errMsg', 'errMsg']
  }

multiple

return error object list.

  [
    {
      name: 'id1',
      errors: ['errMsg', 'errMsg']
    }, {
      name: 'id2',
      errors: ['errMsg', 'errMsg']
    }
  ]
0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago