{"id":14970032,"url":"https://github.com/bitnbytesio/node-input-validator","last_synced_at":"2025-04-05T15:10:09.425Z","repository":{"id":25140511,"uuid":"103280823","full_name":"bitnbytesio/node-input-validator","owner":"bitnbytesio","description":"Validation library for node.js","archived":false,"fork":false,"pushed_at":"2024-06-27T11:02:58.000Z","size":3126,"stargazers_count":91,"open_issues_count":12,"forks_count":30,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T14:09:28.960Z","etag":null,"topics":["express","form","koa","nodejs","validation","validator"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitnbytesio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-12T14:26:18.000Z","updated_at":"2025-03-21T08:09:47.000Z","dependencies_parsed_at":"2024-06-20T23:29:34.982Z","dependency_job_id":"725e8eae-7be7-4344-88d7-c4ccc6e4439e","html_url":"https://github.com/bitnbytesio/node-input-validator","commit_stats":{"total_commits":181,"total_committers":17,"mean_commits":"10.647058823529411","dds":0.2596685082872928,"last_synced_commit":"6448dc9cb6844acfc5327c28af7e63cdae8662f6"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fnode-input-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fnode-input-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fnode-input-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fnode-input-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitnbytesio","download_url":"https://codeload.github.com/bitnbytesio/node-input-validator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353749,"owners_count":20925329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","form","koa","nodejs","validation","validator"],"created_at":"2024-09-24T13:42:55.662Z","updated_at":"2025-04-05T15:10:09.373Z","avatar_url":"https://github.com/bitnbytesio.png","language":"JavaScript","readme":"# Validation Library\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Known Vulnerabilities](https://snyk.io/test/npm/node-input-validator/badge.svg)](https://snyk.io/test/npm/node-input-validator)\n[![Coverage Status][codecov-img]][codecov-url]\n[![David deps][david-image]][david-url]\n[![node version][node-image]][node-url]\n\n[travis-image]: https://api.travis-ci.org/bitnbytesio/node-input-validator.svg?branch=master\n[travis-url]: https://travis-ci.org/bitnbytesio/node-input-validator?branch=master\n\n[codecov-img]: https://codecov.io/gh/bitnbytesio/node-input-validator/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/bitnbytesio/node-input-validator\n\n[david-image]: https://david-dm.org/bitnbytesio/node-input-validator.svg?style=flat-square\u0026branch=master\n[david-url]: https://david-dm.org/bitnbytesio/node-input-validator?branch=master\n\n[npm-image]: https://img.shields.io/npm/v/node-input-validator.svg?style=flat-square\n[npm-url]: https://www.npmjs.com/package/node-input-validator\n[node-image]: https://img.shields.io/badge/node.js-%3E=_8.16-green.svg?style=flat-square\n[node-url]: http://nodejs.org/download/\n\nValidation library for node.js\n\nNIV (Node Input Validator) is a validation library for node.js. You can also extend library to add custom rules.\n\n**Note**: For use case of any rule, please check test cases, If you have any doubt or confusion with documentation or rule behaviour.\n\n## Installation\n\n```shell\nnpm i node-input-validator\n```\n\n## Features\n\n- large collection of rules\n- add your own custom rules\n- supports nested inputs\n- declare rules as strings or array\n- post validation rules\n- modify or add new messages in your own language\n- change attribute names globally or locally\n- current supported languages: English, Persian(farsi)\n\n## Usage\n\n- [Example](#simple-example)  \n- [With express](#with-in-express-application)  \n- [With async/await](#with-async-await)  \n- [Koa middleware](#for-koa2)  \n- [Object validation examples](#objects-validation)  \n- [Array validation examples](#array-validation)  \n- [Add/Modify messages](#add-or-modify-messages)  \n- [Change default language examples](#set-default-language)  \n- [Toggle multiple errors](#toggle-multiple-errors-support)  \n- [Change attribute names in messages examples](#set-attribute-nicecustom-name)  \n- [Add custom rules](#add-your-own-custom-validation-rules)  \n- [Rules](#rules)  \n\n### Simple Example  \n\n```javascript\nconst { Validator } = require('node-input-validator');\n\nconst v = new Validator(\n  { name: '' },\n  { name: 'required|minLength:5' },\n);\n\nv.check().then(function (matched) {\n  console.log(matched);\n  console.log(v.errors);\n});\n```\n\n### With in express application\n\n```javascript\nconst { Validator } = require('node-input-validator');\n\napp.post('login', function (req, res) {\n  const v = new Validator(req.body, {\n    email: 'required|email',\n    password: 'required'\n  });\n\n  v.check().then((matched) =\u003e {\n    if (!matched) {\n      res.status(422).send(v.errors);\n    }\n  });\n});\n```\n\n### With async-await\n\n```javascript\nconst { Validator } = require('node-input-validator');\n\nrouter.post('login', async (ctx) =\u003e {\n  const v = new Validator(ctx.request.body, {\n    email: 'required|email',\n    password: 'required'\n  });\n\n  const matched = await v.check();\n\n  if (!matched) {\n    ctx.status = 422;\n    ctx.body = v.errors;\n    return;\n  }\n});\n```\n\n### For Koa2\n\n#### Attach koa middleware\n\n```javascript\nconst niv = require('node-input-validator');\n\n// keep this under your error handler\napp.use(niv.koa());\n```\n\n#### Then in controller\n\n```javascript\n// if validation fails, this will auto abort request with status code 422 and errors in body\nawait ctx.validate({\n  name: 'required|maxLength:50',\n  username: 'required|maxLength:15',\n  email: 'required|email',\n  password: 'required'\n});\n\n// validation passes\n// do some code\n```\n\n#### With custom inputs\n\n```javascript\n// if validation fails, this will auto abort request with status code 422 and errors in body\nawait ctx.validate({\n  name: 'required|maxLength:50',\n  username: 'required|maxLength:15',\n  email: 'required|email',\n  password: 'required'\n}, ctx.request.body);\n\n// validation passes\n// do some code\n```\n\n#### With custom inputs and custom messages\n\n```javascript\n// if validation fails, this will auto abort request with status code 422 and errors in body\nawait ctx.validate({\n  name: 'required|maxLength:50',\n  username: 'required|maxLength:15',\n  email: 'required|email',\n  password: 'required'\n}, ctx.request.body, { email: 'E-mail is required' });\n\n// validation passes\n// do some code\n```\n\n#### In case you wants control over validator, Then use\n\n```javascript\n// if validation fails, this will auto abort request with status code 422 and errors in body\nconst v = await ctx.validator(ctx.request.body, {\n  name: 'required|maxLength:50',\n  username: 'required|maxLength:15',\n  email: 'required|email',\n  password: 'required'\n});\n\n// in case validation fails\nif (v.fails()) {\n  ctx.status = 422;\n  ctx.body = v.errors;\n  return;\n}\n\n// do some code\n```\n\n##### This method (ctx.validator(inputs, rules, messages={})) also support same options as like ctx.validate\n\n### Objects Validation\n\n#### Example 1\n\n```javascript\nconst v = new Validator(\n  {\n    product: {\n      id: '1',\n      name: '',\n      price: '',\n      active: 'yes',\n    }\n  },\n  {\n    'product': 'required|object',\n    'product.id': 'required|integer',\n    'product.name': 'required',\n    'product.price': 'required|integer',\n    'product.active': 'required|integer'\n  },\n);\n\nconst matched = await v.check();\n```\n\n### Array Validation\n\n#### Example 1\n\n```javascript\nlet v = new Validator(\n  {\n    roles: ['admin', 'manager', 'member']\n  },\n  {\n    'roles': 'required|array',\n    'roles.*': 'required|string'\n  },\n);\n\nlet matched = await v.check();\n```\n\n#### Example 2\n\n```javascript\nlet v = new Validator(\n  {\n    plan: [\n      { price: '25', title: 'OK' },\n      { price: '', title: '' },\n      { price: '30' },\n      { price: '', title: 'Title' }\n    ]\n  },\n  {\n    'plan': 'required|array',\n    'plan.*.price': 'required|integer',\n    'plan.*.title': 'required'\n  },\n);\nlet matched = await v.check();\n```\n\n### Add or Modify messages\n\nPlaceholder in messages, :attribute will be replaced with field/attribute name, :value with field value and :arg0, :arg1 ...n with arguments passed to rule.\n\n#### Add/Update rule based messages\n\n```javascript\nconst niv = require('node-input-validator');\n/**\n * @param {Object} messages\n * @param {string?=en} language\n */\nniv.extendMessages({\n  required: 'The :attribute field must not be empty.',\n  email: 'E-mail must be a valid email address.',\n  even: 'The value of the field must be even number.',\n  status: 'Invalid status'\n}, 'en');\n```\n\n#### Add custom messages\n\n```javascript\nconst niv = require('node-input-validator');\n//Note: Default language is English (en).\nniv.addCustomMessages({\n  'username.required': 'When username attribute required rule failed.',\n  username: 'Default message for username attribute.'\n});\n```\n\n#### for message in another language\n\nYou can easliy add messages in another language.\n\n```javascript\nconst niv = require('node-input-validator');\nniv.extendMessages({\n  required: ':attribute ਫੀਲਡ ਖਾਲੀ ਨਹੀਂ ਹੋਣਾ ਚਾਹੀਦਾ.',\n}, 'pb');\n```\n\n### Set default language\n\n```javascript\nconst niv = require('node-input-validator');\nniv.setLang('pb');\n```\n\n### Toggle Multiple Errors Support\n\nBy default, Validator will run in bailable mode ie. break if some rule failed. You can change this behaviour:\n\n#### Globally\n\n```javascript\nconst niv = require('node-input-validator');\nniv.bailable(false);\n```\n\nNow instead of breaking, it will continues apply other rules.\n\n#### Errors example\n\n```javascript\n{\n  name: [\n    {\n      rule: 'minLength',\n      message: '...',\n    },\n    {\n      rule: 'alpha',\n      message: '...',\n    }\n  ]\n}\n```\n\n#### Locally\n\nTo toggle multiple errors on specific instance only.\n\n```javascript\nconst niv = require('node-input-validator');\nconst v = new niv.Validator(inputs, rules);\nv.bail(false);\n```\n\n### Set attribute nice/custom name\n\nYou can also declare Nice Names / Custom Attributes names.\n\n```javascript\nconst niv = require('node-input-validator');\nniv.niceNames({\n  phone: 'phone number',\n  dob: 'Date of Birth'\n});\n```\n\nIf your are editing other languages, set lang parameter.\n\n```javascript\nconst niv = require('node-input-validator');\nniv.niceNames({\n  phone: 'phone number',\n  dob: 'Date of Birth'\n},'fa');\n```\n\nIn error messages you will get \"phone number\" instead of phone. For Example: In case required rule failed, Error message will be: The phone number field is mandatory.\n\n#### For current instance only\n\n```javascript\nconst niv = require('node-input-validator');\n\nconst v = new niv.Validator(inputs, rules);\nv.niceNames({\n  phone: 'phone number',\n  dob: 'Date of Birth'\n});\n```\n\nThis will only change attribute names for current instance.\n\n### Add your own custom validation rules\n\n```javascript\n// second params will be the instance of Validator\nniv.extend('even', ({ value }) =\u003e {\n  if ((parseInt(value) % 2) == 0) {\n    return true;\n  }\n  return false;\n});\n```\n\n#### Example of using other fields in rule\n\n```javascript\nconst niv = require('node-input-validator');\n\nniv.extend('sumOfFields', ({ value, args }, validator) =\u003e {\n  if (args.length !== 2) {\n    throw new Error('Invalid seed for rule sumOfFields');\n  }\n\n  const anotherValue = Number(validator.inputs[args[0]]);\n\n  const eq = Number(args[1]);\n\n  if ((Number(value) + anotherValue) !== eq) {\n    return false;\n  }\n\n  return true;\n});\n\nlet v = new niv.Validator(\n  { num1: '50', num2: '50' },\n  { num1: 'sumOfFields:num2,100|required' },\n);\n\nlet matched = await v.check();\n\nassert.equal(matched, true);\n```\n\n#### Example of using async rules\n\n```javascript\n// use this rules as unique:seed\n// unique:\u003cMongoose Model\u003e,\u003cField Name\u003e,\u003cID to Ignore, This is optional\u003e\n\nconst niv = require('node-input-validator');\nconst mongoose = require('mongoose');\n\nniv.extend('unique', async ({ value, args }) =\u003e {\n  // default field is email in this example\n  const field = args[1] || 'email';\n\n  let condition = {};\n\n  condition[field] = value;\n\n  // add ignore condition\n  if (args[2]) {\n    condition['_id'] = { $ne: mongoose.Types.ObjectId(args[2]) };\n  }\n\n  let emailExist = await mongoose.model(args[0]).findOne(condition).select(field);\n\n  // email already exists\n  if (emailExist) {\n    return false;\n  }\n\n  return true;\n});\n\n// example usage of upper extended rule\n\nnew niv.Validator({\n  email: 'required|email|unique:User,email'\n}, inputs);\n\n// in case to ignore specific id\n\nnew niv.Validator({\n  email: 'required|email|unique:User,email,5c2f29e9cefa7718a54f8ff1'\n}, inputs);\n```\n#### Example of using rules as array\n\n```javascript\nconst niv = require('node-input-validator');\n\nlet v = new niv.Validator(\n  { foo: 'bar'},\n  { foo: ['required', 'string', [\"minLength\", 5]] },\n);\n\nlet matched = await v.check();\n\nassert.equal(matched, true);\n\nv = new niv.Validator(\n  { foo: 'bar'},\n  { foo: ['required', 'string', \"minLength:5\" ] },\n);\n\nmatched = await v.check();\n\nassert.equal(matched, true);\n```\n\n## Rules\n\nYou can check test cases for rule usage/examples.\n\n**required**  \nThe field under validation cannot be left blank.\n\n```javascript\n// should fail\nnew Validator(\n  { name: '' },\n  { name: 'required' },\n);\n```\n\n**requiredIf:field,value**  \nThe field under validation cannot be left blank, if provided seed value equals to provided value seed.\n\n```javascript\n// requiredIf rule validation fails, becoz email cannot be left blank if age is 16\nnew Validator(\n  { email: '', age: '16' },\n  { email: 'requiredIf:age,16' },\n);\n```\n\n**requiredNotIf:field,value**  \nThe field under validation may left blank, if provided seed value equals to provided value seed.\n\n```javascript\n// requiredNotIf rule validation fails, becoz transport must be present in case age is not 16\nnew Validator(\n  { transport: '', age: '15' },\n  { transport: 'requiredNotIf:age,16' },\n);\n```\n\n**requiredWith:field**  \n**requiredWith:field,field,field**  \n The field under validation may required in case provided seed present.\n\n```javascript\n// requiredWith rule validation fails, becoz email must in case age present.\nnew Validator(\n  { email: '', age: '17' },\n  { email: 'requiredWith:age' },\n);\n```\n\n**requiredWithout:field**  \n**requiredWithout:field,field,field**  \nThe field under validation may left blank in case provided seed present.\n\n```javascript\n// requiredWithout rule validation fails, becoz email is must in case phone,pan not provided.\nnew Validator(\n  { email: '', username: '' },\n  { email: 'requiredWithout:phone,pan', username: 'requiredWithout:email' },\n);\n```\n\n**accepted**  \nThe field under validation must be yes, on, 1, or true.\n\n**accepted:seeds**  \nThe field under validation must be accepted if value exists in provided seed.\n\n**after:YYYY-MM-DD**  \nThe field under validation must be date after provided seed.\n\n```javascript\nnew Validator(\n  { joining: '' },\n  { joining: 'required|after:2018-02-10' },\n);\n```\n\n**alpha**  \n**alpha:locale**  \nThe field under validation must be entirely alphabetic characters.\n\n**alphaDash**  \nThe field under validation may have alpha-numeric characters, as well as dashes and underscores.\n\n**alphaNumeric**  \n**alphaNumeric:locale**\nThe field under validation only contains letters and numbers.\n\n**array**  \nThe field under validation must be an array.\n\n**arrayUnique**  \n\u003csub\u003eAdded in: v3.5\u003c/sub\u003e  \nThe field under validation must be an array and must contains unique values. No need to use array rule. This rule will take care of that.\n\n**arrayUniqueObjects:attributes**  \n\u003csub\u003eAdded in: v3.5\u003c/sub\u003e  \nThe field under validation must be an array and should have objects with unique attributes as per seed. No need to use array rule. This rule will take care of that.\n\n**ascii**  \nThe field under validation only contains ascii characters.\n\n**base64**  \nThe field under validation must be valid base64 encoded string.\n\n**between:min,max**  \nThe field under validation must be betwwen min and max seed. This will work with number valus as well as with arrays using array count.\n\n**boolean**  \n**boolean:custom**  \nThe field under validation must be boolean (true, false, 'true', 'false', 0, 1, '0', '1') or in custom seed.\n\n**contains:value**  \nThe field under validation must contains provided seeds.\n\n```javascript\nlet v = new Validator({bio:'My profile is: example.com'}, {bio:'required|contains:profile'});\n```\n\n**creditCard**  \nThe field under validation must be valid credit card string.\n\n**date**  \nThe field under validation must be a valid date (YYYY-MM-DD).\n\n**dateAfterToday:number,unit**  \nThe field under validation must be a valid date after provided seed.\n\n```javascript\nnew Validator(\n  { expiry: '2019-02-28' },\n  { expiry: 'required|dateAfterToday:2,days' },\n);\n```\n\nsee moment docs(https://momentjs.com/docs/#/manipulating/add/) for supported units.\n\n**dateBeforeToday:number,unit**  \nThe field under validation must be a valid date before provided seed.\n\n```javascript\nlet v = new Validator({valid:'2019-02-28'}, {valid:'required|dateBeforeToday:2,months'});\n```\n\n**dateFormat:format**  \nThe field under validation must match the given date format.\n\nNote: use array of rules style declaration to deal with colon (:) in time formats.\n\n```javascript\nnew Validator(\n  { dob: '' },\n  { dob: 'required|dateFormat:YYYY-MM-DD' },\n);\n```  \n\nCheck https://momentjs.com/docs/ for supported formats\n\n**dateiso**  \n\u003csub\u003eAdded in: v3.6\u003c/sub\u003e  \nThe field under validation must be a valid iso date.\n\n**datetime**  \n\u003csub\u003eAdded in: v3.6\u003c/sub\u003e  \nThe field under validation must match YYYY-MM-DD HH:mm:ss format.\n\n**decimal**  \nThe field under validation must be a decimal value.\n\n**digits:length**  \nThe field under validation must be numeric and must have an exact length.\n\n**digitsBetween:min,max**  \nThe field under validation must have a length between provided min and max values.\n\n**domain**  \nThe field under validation must a qualified domain.\n\n**dimensions:seed**  \n\u003csub\u003eAdded in: v3.7\u003c/sub\u003e  \nThe image under validation must meet the dimension constraints as specified by in seed.\n\n```js\nnew Validator(\n  req.body,\n  { file: 'dimensions:minWidth=50,minHeight=50' },\n);\n\nconst matched = await v.check();\n\nassert.equal(matched, false);\n```\n\nNote: image mimes validation is required before.\n\nAvailable constraints are: minWidth, maxWidth, minHeight, maxHeight, width, height.\n\n**email**  \nThe field under validation must be formatted as an e-mail address.\n\n**equals**  \nThe field under validation must be equal to given value.\n\n**gt:another_field**  \n\u003csub\u003eAdded in: v3.4\u003c/sub\u003e  \nThe field under validation must be greater then another field value. This rule is for Numbers comparision.\n\n**gte:another_field**  \n\u003csub\u003eAdded in: v3.4\u003c/sub\u003e  \nThe field under validation must be greater or equals to another field value. This rule is for Numbers comparision.\n\n**hash:algo**  \nThe field under validation must be a valid hash as per provided seed.\n\n```javascript\nnew Validator(\n  {\n    id: 'fd1baf48377a9f644f9af89abbee29f6'\n  },\n  {\n    id: 'required|hash:md5'\n  },\n);\n```\n\nSupported algorithms: md4, md5, sha1, sha256, sha384, sha512, ripemd128, ripemd160, tiger128, tiger160, tiger192, crc32, crc32b.\n\n**hex**  \nThe field under validation must be valid hex.\n\n**hexColor**  \nThe field under validation must be valid hex color code.\n\n**in:a,b...n**  \nThe field under validation must exist in the given list of values.\n\n```javascript\nnew Validator(\n  { status: '' },\n  { status: 'required|in:active,inactive,blocked' },\n);\n```\n\n**integer**  \nThe field under validation must be an integer.\n\n**ip**  \nThe field under validation must be an IP address.\n\n**iso8601**  \nThe field under validation must be valid Iso8601 date.\n\n**json**  \nThe field under validation must be a valid JSON string.\n\n**length:max**  \n**length:max,min**  \n\u003csub\u003eAdded in: v3.5\u003c/sub\u003e  \nThe field under validation must be less then or equals to max seed provided in rule. In case of min,max seed, field under validation must be less or equals to max seed and less then min seed. Can only be used with strings|arrays or any other object that supports length (str.length) property.\n\n**latLong**  \nThe field under validation must be a valid latitude-longitude coordinate.\n\n**lengthBetween:min,max**  \nThe field under validation value length must be between provided values.\n\n```javascript\nlet v = new Validator({age:''}, {age:'required|between:17,30'});\n```\n\n**lt:another_field**  \n\u003csub\u003eAdded in: v3.4\u003c/sub\u003e  \nThe field under validation must be less then another field value. This rule is for Numbers comparision.\n\n**lte:another_field**  \n\u003csub\u003eAdded in: v3.4\u003c/sub\u003e  \nThe field under validation must be less or equals to another field value. This rule is for Numbers comparision.\n\n**macAddress**  \nThe field under validation should be a valid Mac Address.\n\n**max:seed**  \nThe field under validation must be less than given value.\n\n```javascript\nnew Validator(\n  { age: '' },\n  { age: 'required|max:35' },\n);\n```\n\n**maxLength:seed**  \nThe length of field under validation should be less than given value.\n\n```javascript\nnew Validator(\n  { username: '' },\n  { username: 'required|max:10' },\n);\n```\n\n**mime:seed**  \nThe file under validation must have a MIME type corresponding to one of the listed extensions.\n\n```javascript\nnew Validator(\n  req.body,\n  { file: 'required|mime:jpg,png' },\n);\n```\n\n**min**  \nThe field under validation must be greater than given value.\n\n**minLength**  \nThe length of field under validation should be greater than given value.\n\n**mongoId**  \nThe field under validation should be a valid MongoDB ID.\n\n**notContains:seed**  \nThe field under validation may not contains provided seeds.\n\n**notIn:seeds**  \nThe field under validation must not exist in the given list of values.\n\n**nullable**  \nThe field under validation is required only is not left empty.\n\n**numeric**  \nThe field under validation must be numeric.\n\n**phoneNumber**  \nThe field under validation must be a valid phone number.\n\n**regex**  \nThe field under validation must match the given regular expression.\n\nNote: Currently regex rules break on using colon (:) or pipe delimiters. Use array of rules style declaration instead of string.\n\n```javascript\nnew Validator(\n  req.body,\n  { username: ['required', 'regex:[a-z]'] },\n  { password: 'required|same:confirm_password' },\n);\n```\n\n**same**  \nThe given field must match the field under validation.\n\n**size:max**  \n**size:max,min**  \nThe file field under validation must have a file size matching the given maximum value or should be between size range.\nSupported unit sufix: b(Bytes),kb/k(KilloBytes),mb/m(MegaBytes),gb/g(GigaBytes).\n\n```javascript\n// in below case, image file size should be under 4kb limit\nnew Validator({image:''}, {image:'required|size:4kb'});\n```\n\n```javascript\n// in below case, image file size should be between 1kb - 4kb\nnew Validator({image:''}, {image:'required|size:4kb,1kb'});\n```\n\n```javascript\nnew Validator({video:''}, {video:'required|size:10mb'});\n```\n\n**sometimes**  \nThe field under validation is required if present.\n\n**string**  \nThe field under validation must be string.\n\n**url**  \nThe field under validation must be a valid URL.\n\n**Post Rules**  \nThere is set of rules which can be used to validate constraints of whole input, rather than validity of singular fields.\n\n```javascript\nconst v = new Validator(\n  { name: '' },\n  { '*': 'any:name,surname' },\n);\n\nv.check().then(function (matched) {\n  console.log(matched);\n  console.log(v.errors);\n});\n```\n\nPost validator errors are returned in the `*` key. There is also possibility to add custom function as validator\nwith help of `addPostRule` method. Function will be called in context of validator object with input as parameter.\n\n```javascript\nconst v = new Validator(\n  { username: 'arnold', password: 'arnold123' },\n  { username: 'required', password: 'required' },\n);\n\nv.addPostRule((provider) =\u003e {\n  if (provider.inputs.password.indexOf(provider.inputs.username) \u003e= 0) {\n    provider.error('password', 'custom', 'Password cannot contain username');\n  }\n});\n```\n\n**any**  \nAny of the fields must be present in input.\n\n**all**  \nAll of the fields must be present in input.\n\n### Typescript Support\n\nPartial Support.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitnbytesio%2Fnode-input-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitnbytesio%2Fnode-input-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitnbytesio%2Fnode-input-validator/lists"}