# validate-str

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

Latest version **0.0.10** (published 2018-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install validate-str
pnpm add validate-str
yarn add validate-str
bun add validate-str
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.10 |
| Published | 2018-07-27 |
| First published | 2018-07-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 41.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | qizf |
| Maintainers | qizf |
| Keywords | validate, validator |

## Links

- npm: https://www.npmjs.com/package/validate-str
- Repository: https://github.com/qizf7/validate-str
- Homepage: https://github.com/qizf7/validate-str#readme
- Issues: https://github.com/qizf7/validate-str/issues
- npm.io page: https://npm.io/package/validate-str

## Dependencies (1)

- [regexp-hub](https://npm.io/package/regexp-hub.md) 0.0.1

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.0.10 (latest) — 2018-07-27
- 0.0.9 — 2018-07-25
- 0.0.8 — 2018-07-25
- 0.0.7 — 2018-07-25
- 0.0.6 — 2018-07-24
- 0.0.5 — 2018-07-24
- 0.0.4 — 2018-07-23
- 0.0.3 — 2018-07-23
- 0.0.2 — 2018-07-23
- 0.0.1 — 2018-07-23

## README

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

### usage
```javascript
  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](https://github.com/qizf7/regexp-hub), you can use these regexp names as method directly.

## options

### options.mode

#### single
only return the first error object when validation fails.
```javascript
  {
    name: 'id1',
    errors: ['errMsg', 'errMsg']
  }
```
#### multiple
return error object list.
```javascript
  [
    {
      name: 'id1',
      errors: ['errMsg', 'errMsg']
    }, {
      name: 'id2',
      errors: ['errMsg', 'errMsg']
    }
  ]
```

---
_Source: https://npm.io/package/validate-str · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
