validator.fn

A simple function to aid form validations

Usage no npm install needed!

<script type="module">
  import validatorFn from 'https://cdn.skypack.dev/validator.fn';
</script>

README

validator.fn Tests

A simple function to aid form validations

Getting Started

Installation

Install via Package managers such as npm or yarn

npm install validator.fn --save
# or
yarn add validator.fn

or use cdn

Minified:

//cdn.jsdelivr.net/npm/validator.fn@latest/validator.fn.umd.min.js

Pretty Printed:

//cdn.jsdelivr.net/npm/validator.fn@latest/validator.fn.umd.js

Usage

This library is compiled to UMD format, you should be able to use it in both Node.js and browser.

import validate from 'validator.fn';

const err = validate('hey', ['isString', 'minLength:3', 'hasLength:3']) // is valid

const err = validate(3, ['isNumber', 'inRange:1-10'])
console.log(err) // -> null

Supported Validations

  • isString
  • isNumber
  • iSEmail
  • isRequired
  • minLength
  • maxLength
  • hasLength
  • inRange
  • hasPattern