{"id":26066428,"url":"https://github.com/psecio/validation","last_synced_at":"2025-04-11T16:26:12.957Z","repository":{"id":57045454,"uuid":"71595107","full_name":"psecio/validation","owner":"psecio","description":"A simple little validation library","archived":false,"fork":false,"pushed_at":"2018-09-28T02:39:08.000Z","size":49,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T12:40:51.035Z","etag":null,"topics":["input-validation","security-tools","validation","validation-library"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/psecio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-21T20:41:41.000Z","updated_at":"2021-11-29T10:31:19.000Z","dependencies_parsed_at":"2022-08-24T03:40:18.785Z","dependency_job_id":null,"html_url":"https://github.com/psecio/validation","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psecio%2Fvalidation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psecio%2Fvalidation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psecio%2Fvalidation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/psecio%2Fvalidation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/psecio","download_url":"https://codeload.github.com/psecio/validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248439512,"owners_count":21103622,"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":["input-validation","security-tools","validation","validation-library"],"created_at":"2025-03-08T20:51:56.102Z","updated_at":"2025-04-11T16:26:12.920Z","avatar_url":"https://github.com/psecio.png","language":"PHP","readme":"## Psecio/Validation\n\nThis library seeks to be a simple and reusable validation library for input based on rules.\n\n### Example\n\n```php\n\u003c?php\n\n$v = \\Psecio\\Validate\\Validator::getInstance();\n\n$data = [\n    'foo' =\u003e 'bar'\n];\n$rules = [\n    'foo' =\u003e 'required|alpha'\n];\n\n$result = $v-\u003eexecute($rules, $data);\nvar_export($result);\n\n?\u003e\n```\n\n### Messages\n\nYou can also define custom messages for the failures using the third `$messages` parameter on the `execute` method. The key names on the array match to the value name + check type. For example:\n\n```php\n\u003c?php\n$v = \\Psecio\\Validate\\Validator::getInstance();\n$data = [\n    'foo' =\u003e 'bar'\n];\n$rules = [\n    'foo' =\u003e 'required|alpha'\n];\n$messages = [\n\t'foo' =\u003e ['alpha' =\u003e 'This is a custom message']\n];\n\n$result = $v-\u003eexecute($rules, $data, $messages);\nvar_export($result);\n```\n\nIn the example above, we define a custom message for the `alpha` check on the `foo` value. If that check were to fail, the error message output would be the new custom message instead of the default.\n\n### Getting Errors\n\nThere are two method available to get the errors when the result of the `execute` method is `false`:\n\n- The `errors` method that will return a nested key/value set of failure messages (top level is the value name with each check failure message under it)\n- The `errorArray` method that will return a flattended set of messages useful for output to a page without requiring too much looping\n\n### Checks\n\nHere is a listing of the check types that Validation supports:\n\n#### alpha\nChecks for *only* alpha characters\n\n#### alphanum\nChecks for *only* alpha-numeric characters\n\n#### numeric\nChecks to ensure the value provided is numeric (integer, float, etc)\n\n#### integer\nChecks for integer-only values. Can also include minimum and maximum values:\n\n```php\n// Minimum of 1, max of 10\n$rules = ['mynumber' =\u003e 'integer[1,10]'];\n```\n\n#### boolean\nChecks for boolean values (`true`, `false`, `0`, `1` and strings `'0'`, `'1'`)\n\n#### array\nChecks to ensure the value provided is an array\n\n#### length\nChecks the value to ensure the (string) length matches requirements. You must provide a minimum value, but a maximum can also be defined\n\n```php\n// Using just the minimum, checking for a length of at least 3\n$rules = ['mystring' =\u003e 'length[3]']\n\n// Using both minimum and maximum, check for a length between 3 and 10\n$rules = ['mystring' =\u003e 'length[3,10]']\n```\n\n#### date\nChecks to be sure the value given is a *date* (as parsed by [strtotime](http://php.net/strtotime))\n\n#### before\nChecks to see if the value (a parseable date) is before the date provided (as parsed by [strtotime](http://php.net/strtotime))\n\n```php\n// Check to see if the date provided is before yesterday\n$rules = [\n    'myinputdate' =\u003e 'before[yesterday]'\n];\n```\n\n#### after\nChecks to see if the value (a parseable date) is after the date provided (as parsed by [strtotime](http://php.net/strtotime))\n\n```php\n// Check to see if the date is in the last three days\n$rules = [\n    'myinputdate' =\u003e 'after[-3 days]'\n];\n```\n\n### in\nChecks to ensure the value provided is in a set of values\n\n```php\n// Check to see if the value is one of \"foo\", \"bar\" or \"baz\"\n$rules = [\n    'myvalue' =\u003e 'in[foo,bar,baz]'\n]\n```\n\n#### json\nChecks to be sure the value is a valid JSON formatted string (using [json_decode](http://php.net/json_decode))\n\n#### required\nChecks to be sure the value exists\n\n#### ip\nChecks to ensure the value provided is a valid IPv4 or IPv6 formatted address\n\n#### email\nCheck to ensure the value provided is a validly formatted email address\n\n#### regex\nCheck to ensure the value matches a certain regular expression at least once\n\n```php\n$rules = [\n    'mystring' =\u003e 'regex[/[0-9a-z]+/]'\n]\n```\n\n#### equals\nThis check can be used to see if the values of two fields match exactly.\n\n```\n$data = [\n    'foo' =\u003e 'test1',\n    'bar' =\u003e 'test1'\n];\n$rules = [\n    'bar' =\u003e 'equals[foo]'\n];\n```\n\n#### callback\n\nThis check can be used to call custom logic via a static class method. For example, if your class is:\n\n```php\n\u003c?php\nclass Foo {\n\tpublic static function check($input) { ... }\n}\n?\u003e\n```\n\nThen your rule would look something like this:\n\n```php\n$rules = [\n\t'mystring' =\u003e 'callback[Foo::check]'\n];\n```\n\nAnd the `check` method should return a boolean result.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsecio%2Fvalidation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpsecio%2Fvalidation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpsecio%2Fvalidation/lists"}