{"id":22031378,"url":"https://github.com/devmark/input-check","last_synced_at":"2025-07-23T15:05:39.485Z","repository":{"id":57274278,"uuid":"82757085","full_name":"devmark/input-check","owner":"devmark","description":"Validator for nodejs and web. Like Laravel Validation style for nodejs","archived":false,"fork":false,"pushed_at":"2019-09-22T03:52:24.000Z","size":141,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-03T15:12:03.728Z","etag":null,"topics":["expressjs","input","javascript","json","laravel","nodejs","request","validation","validator"],"latest_commit_sha":null,"homepage":"","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/devmark.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}},"created_at":"2017-02-22T03:37:16.000Z","updated_at":"2019-09-22T03:52:26.000Z","dependencies_parsed_at":"2022-09-17T10:12:41.564Z","dependency_job_id":null,"html_url":"https://github.com/devmark/input-check","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/devmark/input-check","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmark%2Finput-check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmark%2Finput-check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmark%2Finput-check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmark%2Finput-check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devmark","download_url":"https://codeload.github.com/devmark/input-check/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devmark%2Finput-check/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266699565,"owners_count":23970514,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["expressjs","input","javascript","json","laravel","nodejs","request","validation","validator"],"created_at":"2024-11-30T08:16:43.840Z","updated_at":"2025-07-23T15:05:39.455Z","avatar_url":"https://github.com/devmark.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Input check\nProject base on [indicative](https://github.com/poppinss/indicative) \n\nValidator for nodejs and web.\n\n[![Build Status](https://travis-ci.org/devmark/input-check.svg?branch=master)](https://travis-ci.org/devmark/input-check)\n[![NPM](https://nodei.co/npm/input-check.png?downloads=true)](https://nodei.co/npm/input-check/)\n\n\n\n## Installation\n\nInstalling requires node 4.0 or greater with npm installed.\n\n```javascript\nnpm install --save input-check\n```\n\n## Basics\n\n```javascript\nconst inputCheck = require('input-check')\n```\n\n#### validate (data, rules, [messages])\nValidate method will run the validation cycle, which gets terminated on the first error.\n\n```javascript\n\nconst rules = {\n  username: 'required'\n}\n\nconst data = {\n  username: null\n}\n\ninputCheck\n.validate(data, rules)\n.then(function () {\n  // validation passed\n})\n.catch(function (errors) {\n  // validation failed\n})\n```\n\n\n## Custom messages\n```javascript\nconst messages = {\n  required: 'This field is required to complete the registration process.'\n}\n\ninputCheck\n.validate(data, rules, messages)\n.then(function () {\n  // validation passed\n})\n.catch(function (errors) {\n  // validation failed\n})\n```\n\n## Custom Validation\n```javascript\nconst _ = require('lodash');\n\nconst unique = function (data, field, message, args) {\n\n  return new Promise(function (resolve, reject) {\n\n    // get value of field under validation\n    const fieldValue = _.get(data, field);\n\n    // resolve if value does not exists, value existence\n    // should be taken care by required rule.\n    if(!fieldValue) {\n      return resolve('validation skipped');\n    }\n\n    // checking for username inside database\n    User\n    .where('username', fieldValue)\n    .then(function (result) {\n      if(result){\n        reject(message);\n      }else{\n        resolve('username does not exists');\n      }\n    });\n    .catch(resolve);\n\n  });\n\n};\n```\n\n- data - It is the actual data object passed to validate method.\n- field - Field is a string value of field under validation.\n- message - Error message to return.\n- args - An array of values your rule is expecting, it may be empty depending upon your rule expectations. For example min:4 will have args array as [4].\n\n```javascript\ninputCheck.extend('unique', unique, 'Field should be unique')\n```\n\n\n\n\n## Available Validation Rules\nBelow is a list of all available validation rules and their function:\n\naccepted\n----\nThe field under validation must be yes, on, 1, or true. This is useful for validating \"Terms of Service\" acceptance.\n\n\n~~active_url~~\n----\nThe field under validation must have a valid A or AAAA record.\n\n\nafter:(date|time)\n----\nThe field under validation must be a value after a given date or time. \n```javascript\nconst rules = {\n  'createdAt'  : 'date|after:2016-11-11',\n  'time'  : 'time|after:14:00:00'\n}\n```\n\nafter_or_equal:date\n----\nThe field under validation must be a value after or equal to the given date. For more information, see the after rule.\n\n\nalpha\n----\nThe field under validation must be entirely alphabetic characters.\n\n\nalpha_dash\n----\nThe field under validation may have alpha-numeric characters, as well as dashes and underscores.\n\n\nalpha_num\n----\nThe field under validation must be entirely alpha-numeric characters.\n\n\narray\n----\nThe field under validation must be a array.\n\n\nbefore:date\n----\nThe field under validation must be a value preceding the given date or time.\n```javascript\nconst rules = {\n  'createdAt'  : 'date|before:2016-11-11',\n  'time'  : 'time|before:14:00:00'\n}\n```\n\nbefore_or_equal:date\n----\nThe field under validation must be a value preceding or equal to the given date. The dates will be passed into the `momentjs` function.\n\n\nbetween:min,max\n----\nThe field under validation must have a size between the given min and max. \n\n`Strings`, `numerics`, and `array` size rule.\n\nWarning: Not support File type.\n\nboolean\n----\nThe field under validation must be able to be cast as a boolean. Accepted input are true, false,  1, 0, \"1\", and \"0\".\n\n\nconfirmed\n----\nThe field under validation must have a matching field of foo_confirmation. For example, if the field under validation is password, a matching password_confirmation field must be present in the input.\n\n\ndate\n----\nThe field under validation must be a valid date according to the `momentjs` function.\n\n\ndate_format:format\n----\nThe field under validation must match the given format. You should use either date or  date_format when validating a field, not both.\n\n\ndifferent:field\n----\nThe field under validation must have a different value than field.\n\n\n~~digits:value~~\n----\nThe field under validation must be numeric and must have an exact length of value.\n\n\n~~digits_between:min,max~~\n----\nThe field under validation must have a length between the given min and max.\n\n~~distinct~~\n----\nWhen working with arrays, the field under validation must not have any duplicate values.\n\nemail\n----\nThe field under validation must be formatted as an e-mail address.\n\n~~filled~~\n----\nThe field under validation must not be empty when it is present.\n\nin:foo,bar,...  (in_array)\n----\nThe field under validation must be included in the given list of values. Since this rule often requires you to implode an array.\n\n```javascript\nconst rules = {\n  'company'  : 'string|in:google,yahoo,facebook',\n}\n```\n\nin array example:\n```javascript\nconst rules = {\n  'company.*'  : 'in:google,yahoo,facebook',\n}\n```\n\nnot_in:foo,bar,...\n----\nThe field under validation must not be included in the given list of values.\n\n\ninteger\n----\nThe field under validation must be an integer.\n\nip\n----\nThe field under validation must be an IP address.\n\nipv4\n----\nThe field under validation must be an IPv4 address.\n\nipv6\n----\nThe field under validation must be an IPv6 address.\n\njson\n----\nThe field under validation must be a valid JSON string.\n\nmin:value\n----\nThe field under validation must have a minimum value. \n\n`Strings`, `numerics`, and `array` size rule.\n\nWarning: Not support File type.\n\nmax:value\n----\nThe field under validation must be less than or equal to a maximum value. \n`Strings`, `numerics`, and `array` size rule.\n\nWarning: Not support File type.\n\nnullable\n----\nThe field under validation may be null. This is particularly useful when validating primitive such as strings and integers that can contain null values.\n\nnumeric\n----\nThe field under validation must be numeric.\n\n\npresent\n----\nThe field under validation must be present in the input data but can be empty.\n\n\nregex:pattern\n----\nThe field under validation must match the given regular expression.\n\nNote: When using the regex pattern, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character.\n\n\nrequired\n----\nThe field under validation must be present in the input data and not empty. A field is considered \"empty\" if one of the following conditions are true:\n\nThe value is null.\nThe value is an empty string.\nThe value is an empty array or empty Countable object.\nThe value is an uploaded file with no path.\n\nrequired_if:anotherfield,value,...\n----\nThe field under validation must be present and not empty if the anotherfield field is equal to any value.\n\n\nrequired_unless:anotherfield,value,...\n----\nThe field under validation must be present and not empty unless the anotherfield field is equal to any value.\n\n\nrequired_with:foo,bar,...\n----\nThe field under validation must be present and not empty only if any of the other specified fields are present.\n\n\nrequired_with_all:foo,bar,...\n----\nThe field under validation must be present and not empty only if all of the other specified fields are present.\n\n\nrequired_without:foo,bar,...\n----\nThe field under validation must be present and not empty only when any of the other specified fields are not present.\n\n\nrequired_without_all:foo,bar,...\n----\nThe field under validation must be present and not empty only when all of the other specified fields are not present.\n\n\n~~same:field~~\n----\nThe given field must match the field under validation.\n\n\nsize:value\n----\nThe field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to a given integer value. For an array, size corresponds to the count of the array. For files, size corresponds to the file size in kilobytes.\n\n\nstring\n----\nThe field under validation must be a string. If you would like to allow the field to also be null, you should assign the nullable rule to the field.\n\n\n~~timezone~~\n----\nThe field under validation must be a valid timezone identifier according to the  `momentjs` timezone function.\n\n\n\n~~exists:table,column~~\n----\nThe field under validation must exist on a given database table.\n\n~~unique:table,column,except,idColumn~~\n----\nThe field under validation must be unique in a given database table. If the column option is not specified, the field name will be used.\n\nurl\n----\nThe field under validation must be a valid URL.\n\n\n### Different With Laravel Validation\n\ntime\n----\nThe field under validation must be a valid Time.\nSupport format: `HH:mm:ss`, `HH:mm`, `HH:mm a`\n\nobject\n----\nThe field under validation must be a valid object.\n\nuuid\n----\nThe field under validation must be a valid uuid.\n\n\nincludes:foo\n----\nThe field under validation must be within value.\n\n\nstarts_with:foo\n----\nThe field under validation must be start within value.\n\nends_with:foo\n----\nThe field under validation must be end within value.\n\n\n### File \u0026 Image\n\n#### handle multipart bodies\n\nyou may be interested in the following modules:\n  * [formidable](https://www.npmjs.org/package/formidable#readme)\n  * [multer](https://www.npmjs.org/package/multer#readme)\nWhen you using above modules, you could get the file or image information.\nThen, you must to transfer information below before use file validation:\n```javascript\nconst rules = {\n  file: 'file|image'\n}\n\nconst data = {\n  file: {\n      mimetype: 'image/png', // for mime type validation \n      path: '/var/tmp/xxxx.png', // for dimensions \n  }\n}\n\ninputCheck\n.validate(data, rules)\n.then(function () {\n  // validation passed\n})\n.catch(function (errors) {\n  // validation failed\n})\n\n```\n\nfile\n----\nThe field under validation must be a successfully uploaded file.\n\nimage\n----\nThe file under validation must be an image (jpeg, png, bmp, gif, or svg)\n```javascript\nconst rules = {\n  'file'  : 'image',\n}\n```\n\nmimetypes:text/plain,...\n----\nThe file under validation must match one of the given MIME types:\n\n~~mimes:foo,bar,...~~\n----\nThe file under validation must have a MIME type corresponding to one of the listed extensions.\n\ndimensions\n----\nThe file under validation must be an image meeting the dimension constraints as specified by the rule's parameters:\n```javascript\nconst rules = {\n  'image'  : 'dimensions:min_width=100,min_height=200,ratio=3/2',\n}\n```\n\nAvailable constraints are: min_width, max_width, min_height, max_height, width, height, ratio.\n\n## License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n\n * Copyright (c) Harminder Virk \u003cvirk@adonisjs.com\u003e\n * Copyright (c) Devmark \u003chc.devmark@gmail.com\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevmark%2Finput-check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevmark%2Finput-check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevmark%2Finput-check/lists"}