{"id":16758117,"url":"https://github.com/foo123/formal","last_synced_at":"2025-12-24T08:39:32.236Z","repository":{"id":50658005,"uuid":"303056884","full_name":"foo123/Formal","owner":"foo123","description":"A simple and versatile (Form) Data validation framework based on Rules for PHP, JavaScript, Python","archived":false,"fork":false,"pushed_at":"2024-05-17T13:41:06.000Z","size":60,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-17T16:40:29.515Z","etag":null,"topics":["formdata","validation-library","validation-rules"],"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/foo123.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":"2020-10-11T06:27:11.000Z","updated_at":"2024-05-17T13:40:33.000Z","dependencies_parsed_at":"2025-02-17T16:46:37.420Z","dependency_job_id":null,"html_url":"https://github.com/foo123/Formal","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FFormal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FFormal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FFormal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foo123%2FFormal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foo123","download_url":"https://codeload.github.com/foo123/Formal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243203888,"owners_count":20253367,"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":["formdata","validation-library","validation-rules"],"created_at":"2024-10-13T04:04:12.087Z","updated_at":"2025-12-24T08:39:32.231Z","avatar_url":"https://github.com/foo123.png","language":"JavaScript","readme":"Formal\n======\n\nA simple and versatile (Form) Data validation framework based on Rules for PHP, JavaScript, Python\n\nversion **1.3.1**\n\n![Formal](/formal.jpg)\n\n\n### Contents\n\n1. [Example](#example)\n2. [API Reference](#api-reference)\n\n\n### Example\n\n```html\n\u003cform method=\"post\"\u003e\nFoo: \u003cinput name=\"foo\" type=\"text\" value=\"\" /\u003e\n\nMoo:\n\u003cinput name=\"moo[0][choo]\" type=\"text\" value=\"1\" /\u003e\n\u003cinput name=\"moo[1][choo]\" type=\"text\" value=\"2\" /\u003e\n\u003cinput name=\"moo[2][choo]\" type=\"text\" value=\"3\" /\u003e\n\nKoo:\n\u003cinput name=\"koo[]\" type=\"text\" value=\"\" /\u003e\n\u003cinput name=\"koo[]\" type=\"text\" value=\"\" /\u003e\n\u003cinput name=\"koo[]\" type=\"text\" value=\"\" /\u003e\n\nNums:\n\u003cinput name=\"num[]\" type=\"text\" value=\"0.1\" /\u003e\n\u003cinput name=\"num[]\" type=\"text\" value=\"1.2\" /\u003e\n\nDates:\n\u003cinput name=\"date[]\" type=\"text\" value=\"2012-11-02\" /\u003e\n\u003cinput name=\"date[]\" type=\"text\" value=\"20-11-02\" /\u003e\n\n\u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\n\u003c/form\u003e\n```\n\n```php\n$formal = (new Formal())\n        -\u003eoption('WILDCARD', '*') // default\n        -\u003eoption('SEPARATOR', '.') // default\n        -\u003eoption('break_on_first_error', false) // default\n        -\u003eoption('defaults', [\n            'foo' =\u003e 'bar',\n            'moo.*.foo' =\u003e 'bar',\n            'koo.*' =\u003e 'bar'\n        ])\n        -\u003eoption('typecasters', [\n            'num.*' =\u003e Formal::typecast('composite', [Formal::typecast('float'), Formal::typecast('clamp', [0.0, 1.0])])\n        ])\n        -\u003eoption('validators', [\n            'date.*' =\u003e Formal::validate('match', Formal::datetime('Y-m-d'), '\"{key}\" should match {args} !'),\n            'date.0' =\u003e Formal::validate('eq', Formal::field('date.1'))\n        ])\n;\n$data = $formal-\u003eprocess($_POST);\n$err = $formal-\u003egetErrors();\n\nprint_r($data);\n\necho implode(\"\\n\", $err) . PHP_EOL;\n\necho $err[0]-\u003egetMsg() . PHP_EOL;\necho implode('.', $err[0]-\u003egetKey()) . PHP_EOL;\n\n/* output\n\nArray\n(\n    [foo] =\u003e bar\n    [moo] =\u003e Array\n        (\n            [0] =\u003e Array\n                (\n                    [choo] =\u003e 1\n                    [foo] =\u003e bar\n                )\n\n            [1] =\u003e Array\n                (\n                    [choo] =\u003e 2\n                    [foo] =\u003e bar\n                )\n\n            [2] =\u003e Array\n                (\n                    [choo] =\u003e 3\n                    [foo] =\u003e bar\n                )\n\n        )\n\n    [koo] =\u003e Array\n        (\n            [0] =\u003e bar\n            [1] =\u003e bar\n            [2] =\u003e bar\n        )\n\n    [num] =\u003e Array\n        (\n            [0] =\u003e 0.1\n            [1] =\u003e 1\n        )\n\n    [date] =\u003e Array\n        (\n            [0] =\u003e 2012-11-02\n            [1] =\u003e 20-11-02\n        )\n\n)\n\"date.1\" should match Y-m-d !\n\"date.0\" must be equal to \"date.1\"!\n\n\"date.1\" should match Y-m-d !\ndate.1\n*/\n```\n\n### API Reference\n\n**Typecasters**\n\n```php\n// composite typecaster\nFormal::typecast('composite', [$typecaster1, $typecaster2/*, ..*/]);\n\n// boolean typecaster\nFormal::typecast('bool');\n\n// int typecaster\nFormal::typecast('int');\n\n// float typecaster\nFormal::typecast('float');\n\n// string typecaster\nFormal::typecast('str');\n\n// min value typecaster\nFormal::typecast('min', $minValueOrField);\n\n// max value typecaster\nFormal::typecast('max', $maxValueOrField);\n\n// clamp typecaster\nFormal::typecast('clamp', [$minValueOrField, $maxValueOrField]);\n\n// trim typecaster\nFormal::typecast('trim');\n\n// lowercase typecaster\nFormal::typecast('lower');\n\n// uppercase typecaster\nFormal::typecast('upper');\n\n// custom typecaster\nFormal::typecast(function($val, $args, $key, $formalInstance) {\n    // typecast and return new $val\n    return $val;\n}, $args = null);\n```\n\n**Validators**\n\n```php\n// optional validator, only if value is not missing\nFormal::validate('optional', $requiredValidator);\n\n// required validator, fails if value is missing or null\nFormal::validate('required');\n\n// is numeric validator\nFormal::validate('numeric');\n\n// is object validator\nFormal::validate('object');\n\n// is array validator\nFormal::validate('array';\n\n// is file validator\nFormal::validate('file');\n\n// is empty validator\nFormal::validate('empty');\n\n// max items validator\nFormal::validate('maxitems', $maxCountOrField);\n\n// min items validator\nFormal::validate('minitems', $minCountOrField);\n\n// max chars validator\nFormal::validate('maxchars', $maxLenOrField);\n\n// min chars validator\nFormal::validate('minchars', $minLenOrField);\n\n// max file size validator\nFormal::validate('maxsize', $maxSizeOrField);\n\n// min file size validator\nFormal::validate('minsize', $minSizeOrField);\n\n// equals validator\nFormal::validate('eq', $otherValueOrField);\n\n// not equals validator\nFormal::validate('neq', $otherValueOrField);\n\n// greater than validator\nFormal::validate('gt', $otherValueOrField);\n\n// greater than or equal validator\nFormal::validate('gte', $otherValueOrField);\n\n// less than validator\nFormal::validate('lt', $otherValueOrField);\n\n// less than or equal validator\nFormal::validate('lte', $otherValueOrField);\n\n// between values (included) validator\nFormal::validate('between', [$minValueOrField, $maxValueOrField]);\n\n// in array of values validator\nFormal::validate('in', [$val1, $val2/*, ..*/]/*or field*/);\n\n// not in array of values validator\nFormal::validate('not_in', [$val1, $val2/*, ..*/]/*or field*/);\n\n// match pattern validator\nFormal::validate('match', $patternOrField);\n\n// match valid email pattern validator\nFormal::validate('email');\n\n// match valid url pattern validator\nFormal::validate('url');\n\n// not validator\n$validator-\u003e_not_($errMsg = null);\n\n// $validator1 and $validator2\n$validator1-\u003e_and_($validator2);\n\n// $validator1 or $validator2\n$validator1-\u003e_or_($validator2);\n\n// custom validator\nFormal::validate(function($val, $args, $key, $formalInstance, $missingValue, $errMsg) {\n    // validate and return true or false\n    // optionally you can throw FormalException with custom error message\n    throw new FormalException('my custom error message');\n    return false;\n}, $args = null, $errMsg = null);\n```\n\n**see also:**\n\n* [ModelView](https://github.com/foo123/modelview.js) a simple, fast, powerful and flexible MVVM framework for JavaScript\n* [tico](https://github.com/foo123/tico) a tiny, super-simple MVC framework for PHP\n* [LoginManager](https://github.com/foo123/LoginManager) a simple, barebones agnostic login manager for PHP, JavaScript, Python\n* [SimpleCaptcha](https://github.com/foo123/simple-captcha) a simple, image-based, mathematical captcha with increasing levels of difficulty for PHP, JavaScript, Python\n* [Dromeo](https://github.com/foo123/Dromeo) a flexible, and powerful agnostic router for PHP, JavaScript, Python\n* [PublishSubscribe](https://github.com/foo123/PublishSubscribe) a simple and flexible publish-subscribe pattern implementation for PHP, JavaScript, Python\n* [Localizer](https://github.com/foo123/Localizer) a simple and versatile localization class (l10n) for PHP, JavaScript, Python\n* [Importer](https://github.com/foo123/Importer) simple class \u0026amp; dependency manager and loader for PHP, JavaScript, Python\n* [EazyHttp](https://github.com/foo123/EazyHttp), easy, simple and fast HTTP requests for PHP, JavaScript, Python\n* [Contemplate](https://github.com/foo123/Contemplate) a fast and versatile isomorphic template engine for PHP, JavaScript, Python\n* [HtmlWidget](https://github.com/foo123/HtmlWidget) html widgets, made as simple as possible, both client and server, both desktop and mobile, can be used as (template) plugins and/or standalone for PHP, JavaScript, Python (can be used as [plugins for Contemplate](https://github.com/foo123/Contemplate/blob/master/src/js/plugins/plugins.txt))\n* [Paginator](https://github.com/foo123/Paginator)  simple and flexible pagination controls generator for PHP, JavaScript, Python\n* [Formal](https://github.com/foo123/Formal) a simple and versatile (Form) Data validation framework based on Rules for PHP, JavaScript, Python\n* [Dialect](https://github.com/foo123/Dialect) a cross-vendor \u0026amp; cross-platform SQL Query Builder, based on [GrammarTemplate](https://github.com/foo123/GrammarTemplate), for PHP, JavaScript, Python\n* [DialectORM](https://github.com/foo123/DialectORM) an Object-Relational-Mapper (ORM) and Object-Document-Mapper (ODM), based on [Dialect](https://github.com/foo123/Dialect), for PHP, JavaScript, Python\n* [Unicache](https://github.com/foo123/Unicache) a simple and flexible agnostic caching framework, supporting various platforms, for PHP, JavaScript, Python\n* [Xpresion](https://github.com/foo123/Xpresion) a simple and flexible eXpression parser engine (with custom functions and variables support), based on [GrammarTemplate](https://github.com/foo123/GrammarTemplate), for PHP, JavaScript, Python\n* [Regex Analyzer/Composer](https://github.com/foo123/RegexAnalyzer) Regular Expression Analyzer and Composer for PHP, JavaScript, Python\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoo123%2Fformal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoo123%2Fformal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoo123%2Fformal/lists"}