{"id":36896248,"url":"https://github.com/livechat/express-validate","last_synced_at":"2026-01-12T15:42:20.096Z","repository":{"id":5461985,"uuid":"6657113","full_name":"livechat/express-validate","owner":"livechat","description":"Very simple Express middleware to validate stuff.","archived":false,"fork":false,"pushed_at":"2024-02-16T08:14:56.000Z","size":497,"stargazers_count":1,"open_issues_count":5,"forks_count":1,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-02-16T15:56:45.505Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"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/livechat.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2012-11-12T17:09:26.000Z","updated_at":"2024-02-16T15:56:45.505Z","dependencies_parsed_at":"2024-02-06T15:20:38.146Z","dependency_job_id":null,"html_url":"https://github.com/livechat/express-validate","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/livechat/express-validate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livechat%2Fexpress-validate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livechat%2Fexpress-validate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livechat%2Fexpress-validate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livechat%2Fexpress-validate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/livechat","download_url":"https://codeload.github.com/livechat/express-validate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livechat%2Fexpress-validate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28341425,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2026-01-12T15:42:19.426Z","updated_at":"2026-01-12T15:42:20.089Z","avatar_url":"https://github.com/livechat.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-validate\n\nA very simple Express middleware to… well, validate stuff.\n\n## Available validators\n\n- required\n- email\n- equals\n- lengthBetween\n- maxLength\n- minLength\n- between\n- greaterThan\n- lowerThan\n- nonNegative\n- positive\n- negative\n- match\n- ...write your your own!\n\n## Options\n\n```\nvar validator = require(\"../src/express-validate\");\napp.use(validator(options));\n```\n\n`options` is an object with possible properties:\n\n- `rules` - (_object_) - additional rules (described later)\n- `errorParser` - (_function_) - a function taking 3 arguments: `req`, `res` and `errors` (an array of error messages). If validation resulted in no errors, `errors` will be an empty array.\n\n  example usage - returning JSON object\n\n  ```\n  errorParser: function(req, res, err) {\n    return res.send({\n      errors: err\n    });\n  }\n  ```\n\n- `exposeMixedParams` - (_bool_) - if `true`, `req.p` will become an object containing params available in `req.params`, `req.query` and `req.body`.\n\n## Usage examples\n\n### Basic validation\n\nServer code:\n\n```\nvar express = require(\"express\");\nvar validator = require(\"../src/express-validate\");\n\nvar app = express();\napp.use(express.json());\napp.use(validator());\n\napp.get(\"/\", function(req, res) {\n    req.validate({\n        name: \"required\", // single validation rule\n        mail: [\n            \"required\",\n            \"email\" // or an array of rules\n        ]\n    });\n    return res.send(\"it's ok\");\n});\n\napp.listen(3000, function() {\n    return console.log(\"Listening on 3000...\");\n});\n```\n\nRequests:\n\n```\n~ ➢ curl \"localhost:3000\"\nname is requried.\n~ ➢ curl localhost:3000/?name=maciej\nmail is requried.\n~ ➢ curl \"localhost:3000/?name=maciek\u0026mail=me@mpawlowski.pl\"\nit's ok\n\n```\n\n### Customizing error messages\n\nValidation code:\n\n```\nreq.validate({\n    name: {rule: \"required\", message: \"%s is required!\"},\n    age: [\"required\", {\n        rule: \"greaterThan\",\n        than: 18,\n        message: \"Hey, you must be over %than to see the content. Please, provide the correct %s\",\n    }]\n})\n```\n\nRequests:\n\n```\n~ ➢ curl \"localhost:3000/?name=maciej\"\nage is requried.\n~ ➢ curl \"localhost:3000/?name=maciej\u0026age=17\"\nHey, you must be over 18 to see the content. Please, provide the correct age\n~ ➢ curl \"localhost:3000/?name=maciej\u0026age=24\"\nit's ok\n```\n\n### Adding custom rules\n\nServer code:\n\n```\nvar express = require(\"express\");\nvar validator = require(\"../src/express-validate\");\n\nvar app = express();\napp.use(express.json());\napp.use(validator({\n    rules: [\n        {\n            name: \"FOO\",\n            rule: {\n                message: \"%s must equal FOO\",\n                test: function(str) {\n                    if (!str) {\n                        return false; // it's not required\n                    }\n                    if (str !== \"FOO\") {\n                        return true;\n                    }\n                }\n            }\n        },\n        {\n            name: \"lengthBetween\",\n            rule: {\n                message: \"%s must be between %low and %high characters long\",\n                low: 3,\n                high: 5,\n                test: function(str, rule) {\n                    var high, len, low;\n                    if (!str) {\n                        return false;\n                    }\n                    if (typeof str !== \"string\") {\n                        return true;\n                    }\n                    low = rule.low || this.low;\n                    high = rule.high || this.high;\n                    len = str.length;\n                    if (!((low \u003c= len \u0026\u0026 len \u003c= high))) {\n                        return true;\n                    }\n                }\n            }\n        }\n    ]\n}));\n\napp.get(\"/\", function(req, res) {\n    req.validate({\n        foo: \"FOO\",\n        str: {\n            rule: \"lengthBetween\",\n            low: 4,\n            high: 7\n        }\n    });\n    return res.send(\"it's ok\");\n});\n\napp.listen(3000, function() {\n    return console.log(\"Listening on 3000...\");\n});\n\n```\n\nRequests:\n\n```\n~ ➢ curl \"localhost:3000/?foo=1\"\nfoo must equal FOO\n~ ➢ curl \"localhost:3000/?foo=FOO\"\nit's ok\n~ ➢ curl \"localhost:3000/?str=mp\"\nstr must be between 4 and 7 characters long\n~ ➢ curl \"localhost:3000/?str=1234\"\nit's ok\n~ ➢ curl \"localhost:3000/?str=12345678\"\nstr must be between 4 and 7 characters long\n```\n\n## License\n\n_(The MIT License)_\n\nCopyright (c) 2012 Maciej Pawłowski \u003cme@mpawlowski.pl\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivechat%2Fexpress-validate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flivechat%2Fexpress-validate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivechat%2Fexpress-validate/lists"}