# validatinator

> Simple, yet effective, vanilla JavaScript form validation plugin. Validatinator is based off of one of PHP's most famous framework, Laravel. Using Validatinator is as easy as instantiating a Validatinator object, calling the passes or fails methods and i

Latest version **2.0.8** (published 2023-03-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install validatinator
pnpm add validatinator
yarn add validatinator
bun add validatinator
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.8 |
| Published | 2023-03-22 |
| First published | 2015-03-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 101.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 108 |
| Author | David Jenkins |
| Maintainers | djenkinsdev |
| Keywords | forms, validations, form validation, vanilla, laravel form validation, validatinator, vanilla js |

## Links

- npm: https://www.npmjs.com/package/validatinator
- Repository: https://github.com/JenkinsDev/Validatinator
- Homepage: https://github.com/JenkinsDev/Validatinator#readme
- Issues: https://github.com/JenkinsDev/Validatinator/issues
- npm.io page: https://npm.io/package/validatinator

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.8 (latest) — 2023-03-22
- 2.0.7 — 2022-12-29
- 2.0.6 — 2022-09-20
- 2.0.5 — 2022-08-10
- 2.0.4 — 2022-08-08
- 2.0.3 — 2022-07-19
- 2.0.2 — 2022-07-12
- 2.0.1 — 2022-07-12
- 2.0.0 — 2022-07-12
- 1.3.4 — 2017-02-01
- 1.3.3 — 2016-05-16
- 1.3.2 — 2016-02-01
- 1.3.1 — 2015-08-06
- 1.3.0 — 2015-05-21
- 1.2.2 — 2015-03-17
- … 1 more at https://npm.io/package/validatinator/versions

## README

# Validatinator (Reborn)

Current Release: 2.0.8 [Reborn]

Validatinator is a simple, yet effective, HTML form validation library built for JavaScript/TypeScript.

The project was originally loosely based off of Laravel's validation system, and has evolved since.

### How to Use

#### Installation

```javascript
npm install validatinator
```

#### Example Usage

```javascript
import { Validatinator } from "validatinator";

const validatinator = new Validatinator({
  ".my-form-query-selector": {
    ".my-field-query-selector": "required|alpha",
    ".another-field": "min:3|max:10",
    "input[type='checkbox']:last-of-type": "accepted"
  }
});

// async/await
const state = await validatinator.validate(".my-form-query-selector");
console.log(state.valid); // or state.invalid
console.log(state.getAllErrors()); // or state.getFieldErrors(".another-field")

// or as a promise
validatinator.validate(".my-form-query-selector").then((state) => {});
```

### Why does this exist?

Validatinator originally existed through the want of giving to the development community. As of 2022, this project is >6 years old, and has been stagnant for the majority of that time.

While the library may have been stagnant, it has been poised to do well due to the fact that it "just works". Along with all of the technological advancements we've underwent in the past 6 years; now the core pillars of Validatinator's existence are locked to:

* Zero dependencies
* Ease of use
* Framework & runtime agnostic (soon)
* Configurable and override-able

The holy grail of ease-of-use JS/TS validation libraries.

### Validation Methods

* `"accepted"`
* `"alpha"`
* `"alphaDash"`
* `"alphaNum"`
* `"alphaDashNum"`
* `"between:2,10"`
* `"betweenLength:2,10"`
* `"contains:2,4,6,8,10,12"`
* `"dateBefore:2022-02-04"`
* `"dateAfter:2022-02-10"`
* `"difference:.my-other-field-selector,false"`
* `"digitsLength:3"`
* `"digitsLengthBetween:3,10"`
* `"email"`
* `"ipvFour"`
* `"max:500"`
* `"maxLength:2"`
* `"min:200"`
* `"minLength:2"`
* `"notIn:2,4,6,8,10,12"`
* `"number"`
* `"pattern:valid_regex_string"`
* `"required"`
* `"requiredIf:.another-field-selector,value-to-check"`
* `"requiredIfNot:.another-field-selector,value-to-check"`
* `"same:.another-field-selector,false"`
* `"url"`

### Validation Method Notes

* `difference` - The second argument is `strict` which when `false` performs case insensitive comparisons.
* `same` - The second argument is `strict` which when `false` performs case insensitive comparisons.
* `pattern` - The valid regex string will be compared against the field value and if any part of the value matches the string, it will be valid. To strictly match the field value one must include the "starts with" (`^`) and "ends with" (`$`) assertion characters. A backslash inside the regex string must be escaped to be processed as a literal backslash (ex: `"pattern:\\d"` to match any numeric digit).

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