{"id":38297799,"url":"https://github.com/webhkp/pvalidate","last_synced_at":"2026-01-17T02:21:08.615Z","repository":{"id":241253650,"uuid":"804371489","full_name":"webhkp/pvalidate","owner":"webhkp","description":"Simple and flexible validator for PHP","archived":false,"fork":false,"pushed_at":"2024-07-29T12:34:42.000Z","size":63,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-14T17:54:24.016Z","etag":null,"topics":["composer","library","php8","validation"],"latest_commit_sha":null,"homepage":"https://webhkp.com/pvalidate","language":"PHP","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/webhkp.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,"publiccode":null,"codemeta":null}},"created_at":"2024-05-22T13:20:20.000Z","updated_at":"2024-07-29T12:31:09.000Z","dependencies_parsed_at":"2024-05-27T21:05:59.981Z","dependency_job_id":"f392887c-3279-4dd6-b5a8-161ac0d5f899","html_url":"https://github.com/webhkp/pvalidate","commit_stats":null,"previous_names":["webhkp/pvalidate"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/webhkp/pvalidate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webhkp%2Fpvalidate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webhkp%2Fpvalidate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webhkp%2Fpvalidate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webhkp%2Fpvalidate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webhkp","download_url":"https://codeload.github.com/webhkp/pvalidate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webhkp%2Fpvalidate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28492181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T00:50:05.742Z","status":"online","status_checked_at":"2026-01-17T02:00:07.808Z","response_time":85,"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":["composer","library","php8","validation"],"created_at":"2026-01-17T02:21:07.717Z","updated_at":"2026-01-17T02:21:08.597Z","avatar_url":"https://github.com/webhkp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pvalidate\n\n![Pvalidate](https://webhkp.com/wp-content/uploads/2024/05/Pvalidate-e1716833570347.png)\n\n![Latest Release](https://img.shields.io/github/v/release/webhkp/pvalidate)\n![Build Status](https://github.com/webhkp/pvalidate/actions/workflows/tests.yml/badge.svg)\n![Last Commit](https://img.shields.io/github/last-commit/webhkp/pvalidate)\n\n\nPvalidate is a robust and flexible validation library for PHP. It is designed to simplify the process of validating data, ensuring data integrity, and enforcing business rules within your PHP applications.\n\nWhether you are building a small application or a large enterprise system, Pvalidate provides the tools you need to validate your data effectively and efficiently.\n\n### [Check the full documentation here](https://webhkp.com/pvalidate)\n\n### [Check the package on packagist.org](https://packagist.org/packages/webhkp/pvalidate)\n\n## Installation\n\n```bash\ncomposer require webhkp/pvalidate\n```\n\n## Usage \n\n```php\n\u003c?php\n\nrequire_once \"vendor/autoload.php\";\n\n\nuse Webhkp\\Pvalidate\\Rules\\Regex;\nuse Webhkp\\Pvalidate\\Rules\\ValidationRule;\nuse Webhkp\\Pvalidate\\Validator;\nuse Webhkp\\Pvalidate\\Rules\\Required;\nuse Webhkp\\Pvalidate\\Rules\\Range;\nuse Webhkp\\Pvalidate\\Rules\\Allow;\nuse Webhkp\\Pvalidate\\Rules\\Disallow;\n\n\nclass MyClass {\n    public function __construct(\n        #[Required]\n        public string $name\n    ) {\n\n    }\n\n    #[Required]\n    public string $address;\n\n    #[Required]\n    public string $description;\n\n    #[Range(min: 50, max: 60)]\n    const AGE = 40;\n\n    #[Range(min: 50)]\n    public int $prop1 = 40;\n\n    #[Range(max: 10)]\n    #[Disallow([1, 2, 3, 40])]\n    public int $prop2 = 40;\n\n    #[Range()]\n    #[Allow([1, 2, 3, 40])]\n    public int $prop3 = 40;\n\n    #[Required]\n    public array $myArr = [];\n\n    #[Regex('/[A-Z0-9]+/')]\n    public string $regexTestField = 'AB23DE';\n}\n\n\n// Usage\n$myObj = new MyClass(\"Test ABC\");\n$myObj-\u003edescription = \"Some desc string for testing\";\n\n$validationResponse = Validator::validate($myObj);\n\nvar_dump($validationResponse-\u003eisValid());\nvar_dump($validationResponse-\u003egetErrors());\n//var_dump($validationResponse-\u003egetResult());\n\nvar_dump($validationResponse-\u003egetMessages());\n```\n\n## Output\n\n```\nbool(false)\n\n\narray(5) {\n  [\"address\"]=\u003e\n  array(3) {\n    [\"value\"]=\u003e\n    NULL\n    [\"valid\"]=\u003e\n    bool(false)\n    [\"errors\"]=\u003e\n    array(1) {\n      [\"required\"]=\u003e\n      string(25) \"address field is Required\"\n    }\n  }\n  [\"prop1\"]=\u003e\n  array(3) {\n    [\"value\"]=\u003e\n    int(40)\n    [\"valid\"]=\u003e\n    bool(false)\n    [\"errors\"]=\u003e\n    array(1) {\n      [\"min\"]=\u003e\n      string(42) \"prop1 should be larger than or equal to 50\"\n    }\n  }\n  [\"prop2\"]=\u003e\n  array(3) {\n    [\"value\"]=\u003e\n    int(40)\n    [\"valid\"]=\u003e\n    bool(false)\n    [\"errors\"]=\u003e\n    array(1) {\n      [\"disallowed\"]=\u003e\n      string(53) \"prop2 should not be in the disallowed list (1,2,3,40)\"\n    }\n  }\n  [\"myArr\"]=\u003e\n  array(3) {\n    [\"value\"]=\u003e\n    array(0) {\n    }\n    [\"valid\"]=\u003e\n    bool(false)\n    [\"errors\"]=\u003e\n    array(1) {\n      [\"required\"]=\u003e\n      string(23) \"myArr field is Required\"\n    }\n  }\n}\n\narray(5) {\n  [0]=\u003e\n  string(25) \"address field is Required\"\n  [1]=\u003e\n  string(42) \"prop1 should be larger than or equal to 50\"\n  [2]=\u003e\n  string(53) \"prop2 should not be in the disallowed list (1,2,3,40)\"\n  [3]=\u003e\n  string(23) \"myArr field is Required\"\n}\n```\n\n## Individual Rule Usage\n\n### Use \"Allow\" Rule\n\n```php\n\u003c?php\n\nrequire_once \"vendor/autoload.php\";\n\nuse Webhkp\\Pvalidate\\Rules\\Allow;\n\n// Check single data with rule only\n$validation = new Allow([1, 2, 3, 4, 5, 10]);\n$validationResult = $validation-\u003esafeParse(22);\n\nvar_dump($validationResult-\u003eisValid());\nvar_dump($validationResult-\u003egetErrors());\n```\n\nOutput:\n\n```\nbool(false)\n\n\narray(1) {\n  [\"allowed\"]=\u003e\n  string(45) \" should be in the allowed list (1,2,3,4,5,10)\"\n}\n```\n\n### Use 'Regex' Rule\n\n```php\n\u003c?php\n\nrequire_once \"vendor/autoload.php\";\n\nuse Webhkp\\Pvalidate\\Rules\\Regex;\n\n// Regex validation\n$regexRule = new Regex('/^[A-Z0-9]{3}.*/');\n$regexResult = $regexRule-\u003esafeParse('D2ab');\nvar_dump($regexResult-\u003eisValid());\nvar_dump($regexResult-\u003egetErrors());\n\n```\n\nOutput:\n\n```\nbool(false)\n\narray(1) {\n  [\"regex\"]=\u003e\n  string(42) \" should match the regex '/^[A-Z0-9]{3}.*/'\"\n}\n```\n\n## Parse and Throw Error\n\n```php\n\u003c?php\n\nrequire_once \"vendor/autoload.php\";\n\nuse Webhkp\\Pvalidate\\Rules\\Required;\n\n// Check required and throw error\ntry {\n    $requiredValidationResult = (new Required)-\u003eparse(null);\n\n    var_dump($requiredValidationResult-\u003eisValid());\n    var_dump($requiredValidationResult-\u003egetErrors());\n} catch (\\Exception $e) {\n    var_dump($e-\u003egetMessage());\n}\n\n```\n\nOutput:\n\n```\nobject(Webhkp\\Pvalidate\\Exceptions\\PvalidateException)#8 (8) {\n  [\"message\":protected]=\u003e\n  string(18) \" field is Required\"\n  [\"string\":\"Exception\":private]=\u003e\n  string(0) \"\"\n  [\"code\":protected]=\u003e\n  int(1)\n  [\"file\":protected]=\u003e\n  string(80) \"package/pvalidate/src/Rules/ValidationRule.php\"\n  [\"line\":protected]=\u003e\n  int(72)\n  [\"trace\":\"Exception\":private]=\u003e\n  array(1) {\n    [0]=\u003e\n    array(5) {\n      [\"file\"]=\u003e\n      string(43) \"index.php\"\n      [\"line\"]=\u003e\n      int(126)\n      [\"function\"]=\u003e\n      string(5) \"parse\"\n      [\"class\"]=\u003e\n      string(37) \"Webhkp\\Pvalidate\\Rules\\ValidationRule\"\n      [\"type\"]=\u003e\n      string(2) \"-\u003e\"\n    }\n  }\n  [\"previous\":\"Exception\":private]=\u003e\n  NULL\n  [\"additionalData\":\"Webhkp\\Pvalidate\\Exceptions\\PvalidateException\":private]=\u003e\n  NULL\n}\n```\n\n\n## Custom Rule\n\n```php\n\u003c?php\n\nrequire_once \"vendor/autoload.php\";\n\nuse Webhkp\\Pvalidate\\Rules\\Custom;\nuse Webhkp\\Pvalidate\\Rules\\Regex;\nuse Webhkp\\Pvalidate\\Rules\\ValidationRule;\nuse Webhkp\\Pvalidate\\Validator;\nuse Webhkp\\Pvalidate\\Rules\\Required;\nuse Webhkp\\Pvalidate\\Rules\\Range;\nuse Webhkp\\Pvalidate\\Rules\\Allow;\nuse Webhkp\\Pvalidate\\Rules\\Disallow;\n\n\n// Define your own rule attribute\n#[Attribute]\nclass MyCustomPasswordRule extends ValidationRule {\n    public function __construct(private readonly string $minLength) {\n\n    }\n\n    public function isValid(): bool {\n        if (strlen($this-\u003evalue) \u003e= $this-\u003eminLength) {\n            return false;\n        }\n\n        // Must contain one Upper case letter\n        if (!preg_match('/[A-Z]/', $this-\u003evalue)) {\n            return false;\n        }\n\n        // Must contain a digit\n        if (!preg_match('/[0-9]/', $this-\u003evalue)) {\n            return false;\n        }\n\n        // Must contain a special character\n        if (!preg_match('/[!@#$%^\u0026*]$/', $this-\u003evalue)) {\n            return false;\n        }\n\n        return true;\n    }\n\n    public function getErrors(): array {\n        $errors = [];\n\n        if (!$this-\u003eisValid()) {\n            $errors['password'] = $this-\u003ename . ' is not a valid password (minimum length ' . $this-\u003eminLength . ', must contain a uppercase letter, a digit and a special character from \"!@#$%^\u0026*\")';\n        }\n\n        return $errors;\n    }\n\n}\n\nclass MyClass {\n    public function __construct() {\n\n    }\n\n    #[Required]\n    public array $myArr = [];\n\n    #[Regex('/[A-Z0-9]+/')]\n    public string $regexTestField = 'AB23DE';\n\n    #[MyCustomPasswordRule(100)]\n    public string $password = 'mysimplepass';\n}\n\n\n// Usage\n$myObj = new MyClass();\n\n$validationResponse = Validator::validate($myObj);\n\nvar_dump($validationResponse-\u003eisValid());\nvar_dump($validationResponse-\u003egetErrors());\nvar_dump($validationResponse-\u003egetResult());\n\nvar_dump($validationResponse-\u003egetMessages());\n```\n\nOutput:\n\n```\nbool(false)\n\narray(2) {\n  [\"myArr\"]=\u003e\n  array(3) {\n    [\"value\"]=\u003e\n    array(0) {\n    }\n    [\"valid\"]=\u003e\n    bool(false)\n    [\"errors\"]=\u003e\n    array(1) {\n      [\"required\"]=\u003e\n      string(23) \"myArr field is Required\"\n    }\n  }\n  [\"password\"]=\u003e\n  array(3) {\n    [\"value\"]=\u003e\n    string(12) \"mysimplepass\"\n    [\"valid\"]=\u003e\n    bool(false)\n    [\"errors\"]=\u003e\n    array(1) {\n      [\"password\"]=\u003e\n      string(135) \"password is not a valid password (minimum length 100, must contain a uppercase letter, a digit and a special character from \"!@#$%^\u0026*\")\"\n    }\n  }\n}\n```\n\n\n## Validation Builder\n\n```php\n\u003c?php\n\nrequire_once \"vendor/autoload.php\";\n\nuse Webhkp\\Pvalidate\\ValidationBuilder;\n\n$validation = ValidationBuilder::required()-\u003egt(11)-\u003egte(200)-\u003erange(min: 1, max: 1000)-\u003esafeParse(11);\n\nvar_dump($validation-\u003eisValid());\nvar_dump($validation-\u003egetErrors());\n//var_dump($validation-\u003egetMessages());\n//var_dump($validation-\u003egetResult());\n\n```\n\nOutput:\n\n```\nbool(false)\n\narray(2) {\n  [\"gt\"]=\u003e\n  array(3) {\n    [\"value\"]=\u003e\n    int(11)\n    [\"valid\"]=\u003e\n    bool(false)\n    [\"errors\"]=\u003e\n    array(1) {\n      [\"min\"]=\u003e\n      string(26) \" should be larger than  11\"\n    }\n  }\n  [\"gte\"]=\u003e\n  array(3) {\n    [\"value\"]=\u003e\n    int(11)\n    [\"valid\"]=\u003e\n    bool(false)\n    [\"errors\"]=\u003e\n    array(1) {\n      [\"min\"]=\u003e\n      string(38) \" should be larger than or equal to 200\"\n    }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebhkp%2Fpvalidate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebhkp%2Fpvalidate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebhkp%2Fpvalidate/lists"}