# is.valid

> validation library that is heavily inspired from the old famous codeigniter validation library

Latest version **0.5.3** (published 2016-03-16) · 0 weekly downloads

## Install

```sh
npm install is.valid
pnpm add is.valid
yarn add is.valid
bun add is.valid
```

## 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.5.3 |
| Published | 2016-03-16 |
| First published | 2014-02-23 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | BahaaGalal |
| Maintainers | bahaagalal |
| Keywords | validation, form validation, data validation |

## Links

- npm: https://www.npmjs.com/package/is.valid
- Repository: https://github.com/bahaagalal/is.valid
- Issues: https://github.com/bahaagalal/is.valid/issues
- npm.io page: https://npm.io/package/is.valid

## Dependencies (2)

- [xss](https://npm.io/package/xss.md) 0.0.9
- [moment](https://npm.io/package/moment.md) ~2.8.3

## 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

- 0.5.3 (latest) — 2016-03-16
- 0.5.2 — 2014-11-02
- 0.5.1 — 2014-11-02
- 0.5.0 — 2014-10-29
- 0.4.0 — 2014-10-29
- 0.3.0 — 2014-10-26
- 0.2.3 — 2014-02-25
- 0.2.2 — 2014-02-23
- 0.2.1 — 2014-02-23
- 0.2.0 — 2014-02-23
- 0.1.0 — 2014-02-23

## README

# is.valid

[![Build Status](https://travis-ci.org/bahaagalal/is.valid.png?branch=master)](https://travis-ci.org/bahaagalal/is.valid)

Validation library for node.js inspired from the old famous codeigniter validation library.

## How to use

Install from npm

```bash
npm install is.valid
```

Instantiate a new is.valid object

```js
var IsValid = require('is.valid');

/** construct a new is.valid object passing the data array to validate
  * date array should contain a set of objects formatted as following
  * {fieldName: value}
 */
var data = {
	name: 'foo bar',
	email: 'foo@bar.com'
}
var isValid = new IsValid(data);
```

Add validation rules

```js
/**
  * to add validation rules use addRule function
  * addRule accepts 3 arguments
  * field Name as in data object
  * friendly Name for error messages
  * rules separated by |
  * rule is specified by a name and optionaly options
  * like for minLength you should also submit what is the minimum length
  * using the brackets way [10]
 **/
isValid.addRule('name', 'Name', 'required|minLength[10]');
```

Run validation rules

```js
/**
  * run function go through all validation rules you specified for all fields
  * it accepts a callback function
  * where err is an array contains all error messages formatted like
  * {fieldName: errorMessage }
  * or null if no errors have been found
  * and data is the data object
 **/
isValid.run(function(err, data){

});
```

## Validation functions

**required**: validates that a value exists

**minLength[l]**: validates that a value length is at minimum equal to l

**maxLength[l]**: validates that a value length is at maximum equal to l

**exactLength[l]**: validates that a value length is exactly l

**greaterThan[l]**: validate that a value is greater than l

**lessThan[l]**: validates that a value is less than l

**alpha**: validates that a value contains only alphabet letters [A-Za-z]

**alphaNumeric**: validates that a value contains only alphabet letters or numbers [A-Za-z0-9]

**alphaNumericDash**: validates that a value contains only alphabet letters, numbers or dash [A-Za-z0-9\-]

**numeric**: validates that a value is numeric [0-9]

**integer**: validates that a value is an integer

**decimal**: validates that a value is a decimal number

**natural**: validates that a value is a natural number >= 0

**naturalNoZero**: validates that a value is a natural number and greater than zero

**email**: validates that a value looks like an email

**regex[s]**: validates that a value matches the given regular expressions s

**matches[f]**: validates that a value matches a value of another field f

**list**: validates that a value is a list

**minListLength[l]**: validates that a list has a minimum length l

**maxListLength[l]**: validates that a list doesn't exceed a maximum length l

**date**: validates that a value is an actual date

**beforeDate[l]**: validates that a date is earlier than another date l

**afterDate[l]**: validates that a date is later than another date l

**boolean**: validates that a value is either true or false

**sanitize**: sanitize a value against any possible xss attacks

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