{"id":20159632,"url":"https://github.com/co0lc0der/validator-component","last_synced_at":"2026-06-09T15:01:51.494Z","repository":{"id":134638424,"uuid":"356999668","full_name":"co0lc0der/Validator-component","owner":"co0lc0der","description":"Validator php component","archived":false,"fork":false,"pushed_at":"2022-08-09T14:54:51.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-03T02:26:31.132Z","etag":null,"topics":["php","php-oop","validation","validator"],"latest_commit_sha":null,"homepage":"","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/co0lc0der.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-11T23:06:49.000Z","updated_at":"2022-08-11T11:48:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"8304fdc7-7df8-45d1-ae98-7cd0bb040fce","html_url":"https://github.com/co0lc0der/Validator-component","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/co0lc0der/Validator-component","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co0lc0der%2FValidator-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co0lc0der%2FValidator-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co0lc0der%2FValidator-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co0lc0der%2FValidator-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/co0lc0der","download_url":"https://codeload.github.com/co0lc0der/Validator-component/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co0lc0der%2FValidator-component/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34112225,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["php","php-oop","validation","validator"],"created_at":"2024-11-14T00:09:21.083Z","updated_at":"2026-06-09T15:01:51.475Z","avatar_url":"https://github.com/co0lc0der.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Validator php component\n\nThis is easy-to-use php component for validate POST or GET data in your project. See `index.php` for examples.\n### Public methods:\n- `check()` - inits validation with rules\n- `setDB()` - sets DB connection (using [QueryBuilder](https://github.com/co0lc0der/QueryBuilder-component) class)\n- `errors()` - returns an array of validation's errors\n- `passed()` - returns result of validation (true or false)\n### Supported rules:\n- `required` - true/false\n- `min` - minimal length of value\n- `max` - maximal length of value\n- `matches` - compares 2 fields\n- `int` - check integer type\n- `min_value` - minimal value of integer\n- `max_value` - maximal value of integer\n- `unique` - looking for this value in DB\n- `email` - check email correct format\n- `regex` - any RegEx checking\n## How to use\n### 1. Include Validator class and init it. If you use `unique` rule you have to include [QueryBuilder](https://github.com/co0lc0der/QueryBuilder-component) class also (see QueryBuilder README).\n```php\nrequire __DIR__ . '/Validator/Validator.php';\n$validator = new Validator();\n```\nor\n```php\n$config = require __DIR__ . '/QueryBuilder/config.php';\nrequire __DIR__ . '/QueryBuilder/Connection.php';\nrequire __DIR__ . '/QueryBuilder/QueryBuilder.php';\nrequire __DIR__ . '/Validator/Validator.php';\n\n$query = new QueryBuilder(Connection::make($config['database']));\n$validator = new Validator($query);\n```\n### 2. Use `check()` method with rules you need.\n```php\n$validator-\u003echeck($_POST, [\n\t'username'  =\u003e  [\n\t\t'required'  =\u003e  true,\n\t\t'min'   =\u003e  2,\n\t\t'max'   =\u003e  15,\n\t],\n\t'email' =\u003e  [\n\t\t'required'  =\u003e  true,\n\t\t'email' =\u003e  true,\n\t\t'unique'    =\u003e  'users'\n\t],\n\t'password' =\u003e [\n\t\t'required'  =\u003e  true,\n\t\t'min'   =\u003e  3\n\t],\n\t'password_again' =\u003e [\n\t\t'required'  =\u003e  true,\n\t\t'matches'   =\u003e 'password'\n\t],\n\t'number'  =\u003e  [\n\t\t'required'  =\u003e  true,\n\t\t'max'   =\u003e  5,\n\t\t'min_value'   =\u003e  0,\n\t\t'max_value'   =\u003e  15,\n\t],\n\t'date' =\u003e [\n\t\t'required'  =\u003e  true,\n\t\t'regex' =\u003e \"/^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$/\" // YYYY-MM-DD\n\t],\n\t'agree' =\u003e [\n\t\t'required'  =\u003e  true,\n\t]\n]);\n```\nform example:\n```php\n\u003cform action=\"\" method=\"post\" enctype=\"multipart/form-data\"\u003e\n\t\u003cinput type=\"text\" name=\"username\" value=\"\u003c?= $_POST['username'] ?? ''; ?\u003e\"\u003e\u003cbr\u003e\n\t\u003cinput type=\"email\" name=\"email\" value=\"\u003c?= $_POST['email'] ?? ''; ?\u003e\"\u003e\u003cbr\u003e\n\t\u003cinput type=\"password\" name=\"password\" value=\"\u003c?= $_POST['password'] ?? ''; ?\u003e\"\u003e\u003cbr\u003e\n\t\u003cinput type=\"password\" name=\"password_again\" value=\"\u003c?= $_POST['password_again'] ?? ''; ?\u003e\"\u003e\u003cbr\u003e\n\t\u003cinput type=\"number\" name=\"number\" value=\"\u003c?= $_POST['number'] ?? ''; ?\u003e\"\u003e\u003cbr\u003e\n\t\u003cinput type=\"text\" name=\"date\" value=\"\u003c?= $_POST['date'] ?? ''; ?\u003e\" placeholder=\"YYYY-MM-DD\"\u003e\u003cbr\u003e\n\t\u003cinput type=\"checkbox\" name=\"agree\" \u003c?= isset($_POST['agree']) \u0026\u0026 !empty($_POST['agree']) ? 'checked' : '' ?\u003e\u003e I agree\u003cbr\u003e\n\t\u003cinput type=\"submit\" value=\"Send\"\u003e\n\u003c/form\u003e\n```\n### 3. Do something if validation is passed or print errors.\n```php\nif ($validator-\u003epassed()) {\n\t// do something\n} else {\n\techo '\u003cul\u003e';\n\tforeach ($validator-\u003eerrors() as $error) {\n\t\techo \"\u003cli\u003e$error\u003c/li\u003e\";\n\t}\n\techo '\u003c/ul\u003e';\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco0lc0der%2Fvalidator-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fco0lc0der%2Fvalidator-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco0lc0der%2Fvalidator-component/lists"}