{"id":15679539,"url":"https://github.com/nilportugues/php-validator","last_synced_at":"2025-12-17T22:50:51.427Z","repository":{"id":20834424,"uuid":"24120470","full_name":"nilportugues/php-validator","owner":"nilportugues","description":"A powerful and elegant stand-alone validation library with no dependencies.","archived":false,"fork":false,"pushed_at":"2016-03-06T10:15:11.000Z","size":317,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T10:03:09.799Z","etag":null,"topics":["error-handling","form","form-validation","php","php7","quality","validation","validator"],"latest_commit_sha":null,"homepage":"http://nilportugues.com","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/nilportugues.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-16T22:38:58.000Z","updated_at":"2023-04-08T19:09:13.000Z","dependencies_parsed_at":"2022-08-25T08:50:20.613Z","dependency_job_id":null,"html_url":"https://github.com/nilportugues/php-validator","commit_stats":null,"previous_names":["nilportugues/validator"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/nilportugues/php-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Fphp-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Fphp-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Fphp-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Fphp-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nilportugues","download_url":"https://codeload.github.com/nilportugues/php-validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilportugues%2Fphp-validator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265820049,"owners_count":23833557,"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":["error-handling","form","form-validation","php","php7","quality","validation","validator"],"created_at":"2024-10-03T16:32:52.627Z","updated_at":"2025-12-17T22:50:46.348Z","avatar_url":"https://github.com/nilportugues.png","language":"PHP","funding_links":["https://paypal.me/nilportugues"],"categories":[],"sub_categories":[],"readme":" Input Validator\n=========================================\n\n[![Build Status](https://travis-ci.org/nilportugues/php-validator.svg)](https://travis-ci.org/nilportugues/php-validator) [![Coverage Status](https://img.shields.io/coveralls/nilportugues/validator.svg)](https://coveralls.io/r/nilportugues/validator?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nilportugues/validator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nilportugues/validator/?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/9fbb4900-70b9-49f6-b7d5-a9f560cdb036/mini.png)](https://insight.sensiolabs.com/projects/9fbb4900-70b9-49f6-b7d5-a9f560cdb036) [![Latest Stable Version](https://poser.pugx.org/nilportugues/validator/v/stable)](https://packagist.org/packages/nilportugues/validator) [![Total Downloads](https://poser.pugx.org/nilportugues/validator/downloads)](https://packagist.org/packages/nilportugues/validator) [![License](https://poser.pugx.org/nilportugues/validator/license)](https://packagist.org/packages/nilportugues/validator)\n[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://paypal.me/nilportugues)\n \nValidation is a very common task in web applications. Data entered in forms needs to be validated. Data also needs to be validated before it is written into a database or passed to a web service.\n\nNilPortugues\\Validator is a simple, powerful and elegant stand-alone validation library with no external dependencies.\n\n\n\u003ca name=\"index_block\"\u003e\u003c/a\u003e\n* [1. Installation](#block1)\n* [2. Usage](#block2)\n  * [2.1. Validation made for everyone](#block2.1)\n    * [2.1.1. Instantiation of Validator class](#block2.1.1)\n    * [2.1.2. Factory using ValidatorFactory::create](#block2.1.2)\n    * [2.1.3. Extending from the BaseValidator](#block2.1.3)\n  * [2.2. Stop on first error](#block2.2)\n* [3. Validation Message Translation](#block3)  \n* [4. Methods](#block4)\n    * [4.1 isString | string](#block4.1)\n        * [4.1.1. isAlphanumeric | alphanumeric] (#block4.1.1)\n            * [4.1.1.1. Instantiation of Validator class](#block4.1.1.1)\n            * [4.1.1.2. Factory using Validator::create](#block4.1.1.2)\n            * [4.1.1.3. Extending from the BaseValidator](#block4.1.1.3)\n        * [4.1.2. isAlpha | alpha] (#block4.1.2)\n        * [4.1.3. isBetween | between] (#block4.1.3)\n        * [4.1.4. isCharset | charset] (#block4.1.4)\n        * [4.1.5. isAllConsonants | all_consonants] (#block4.1.5)\n        * [4.1.6. contains] (#block4.1.6)\n        * [4.1.7. isControlCharacters | control_characters] (#block4.1.7)\n        * [4.1.8. isDigit | digit] (#block4.1.8)\n        * [4.1.9. endsWith | ends_with] (#block4.1.9)\n        * [4.1.10. equals] (#block4.1.10)\n        * [4.1.11. in] (#block4.1.11)\n        * [4.1.12. hasGraphicalCharsOnly | has_graphical_chars_only] (#block4.1.12)\n        * [4.1.13. hasLength | has_length] (#block4.1.13)\n        * [4.1.14. isLowercase | lowercase] (#block4.1.14)\n        * [4.1.15. notEmpty | not_empty] (#block4.1.15)\n        * [4.1.16. noWhitespace | no_whitespace] (#block4.1.16)\n        * [4.1.17. hasPrintableCharsOnly | has_printable_chars_only] (#block4.1.17)\n        * [4.1.18. isPunctuation | punctuation] (#block4.1.18)\n        * [4.1.19. matchesRegex | matches_regex] (#block4.1.19)\n        * [4.1.20. isSlug | slug] (#block4.1.20)\n        * [4.1.21. isSpace | space] (#block4.1.21)\n        * [4.1.22. startsWith | starts_with] (#block4.1.22)\n        * [4.1.23. isUppercase | uppercase] (#block4.1.23)\n        * [4.1.24. isVersion | version] (#block4.1.24)\n        * [4.1.25. isVowel | vowel] (#block4.1.25)\n        * [4.1.26. isHexDigit | hex_digit] (#block4.1.26)\n        * [4.1.27. hasLowercase | has_lowercase] (#block4.1.27)\n        * [4.1.28. hasUppercase | has_uppercase] (#block4.1.28)\n        * [4.1.29. hasNumeric | has_numeric] (#block4.1.29)\n        * [4.1.30. hasSpecialCharacters | has_special_characters] (#block4.1.30)\n        * [4.1.31. isEmail | email] (#block4.1.31)\n        * [4.1.32. isUrl | url] (#block4.1.32)\n        * [4.1.33. isUUID | uuid] (#block4.1.33)\n    * [4.2 isInteger | integer and isFloat | float](#block4.2)\n        * [4.2.1. isNotZero | not_zero ] (#block4.2.1)\n        * [4.2.2. isPositive | positive] (#block4.2.2)\n        * [4.2.2. isPositiveOrZero | positive_or_zero] (#block4.2.3)\n        * [4.2.4. isNegative | negative] (#block4.2.4)\n        * [4.2.5. isNegativeOrZero | negative_or_zero] (#block4.2.5)\n        * [4.2.6. isBetween | between] (#block4.2.6)\n        * [4.2.7. isOdd | odd] (#block4.2.7)\n        * [4.2.8. isEven | even] (#block4.2.8)\n        * [4.2.9. isMultiple | multiple] (#block4.2.9)\n    * [4.3 isObject | object](#block4.3)\n        * [4.3.1. isInstanceOf | instance_of] (#block4.3.1)\n        * [4.3.2. hasProperty | has_property] (#block4.3.2)\n        * [4.3.3. hasMethod | has_method] (#block4.3.3)\n        * [4.3.4. hasParentClass | has_parent_class] (#block4.3.4)\n        * [4.3.5. isChildOf | child_of] (#block4.3.5)\n        * [4.3.6. inheritsFrom | inherits_from] (#block4.3.6)\n        * [4.3.7. hasInterface | has_interface] (#block4.3.7)\n    * [4.4 isDateTime | date_time](#block4.4)\n        * [4.4.1. isAfter | after] (#block4.4.1)\n        * [4.4.2. isBefore | before] (#block4.4.2)\n        * [4.4.3. isBetween | between] (#block4.4.3)\n        * [4.4.4. isWeekend | weekend] (#block4.4.4)\n        * [4.4.5. isWeekday | weekday] (#block4.4.5)\n        * [4.4.6. isMonday | monday] (#block4.4.6)\n        * [4.4.7. isTuesday | tuesday] (#block4.4.7)\n        * [4.4.8. isWednesday | wednesday] (#block4.4.8)\n        * [4.4.9. isThursday | thursday] (#block4.4.9)\n        * [4.4.10. isFriday | friday] (#block4.4.10)\n        * [4.4.11. isSaturday | saturday] (#block4.4.11)\n        * [4.4.12. isSunday | sunday] (#block4.4.12)\n        * [4.4.13. isToday | today] (#block4.4.13)\n        * [4.4.14. isYesterday | yesterday] (#block4.4.14)\n        * [4.4.15. isTomorrow | tomorrow] (#block4.4.15)\n        * [4.4.16. isLeapYear | leap_year] (#block4.4.16)\n        * [4.4.17. isMorning | morning] (#block4.4.17)\n        * [4.4.18. isAftenoon | aftenoon] (#block4.4.18)\n        * [4.4.19. isEvening | evening] (#block4.4.19)\n        * [4.4.20. isNight | night] (#block4.4.20)\n    * [4.5 isArray | array](#block4.5)\n        * [4.5.1. each] (#block4.5.1)\n        * [4.5.2. hasKeyFormat | has_key_format] (#block4.5.2)\n        * [4.5.3. endsWith | ends_with] (#block4.5.3)\n        * [4.5.4. contains] (#block4.5.4)\n        * [4.5.5. hasKey | has_key] (#block4.5.5)\n        * [4.5.6. hasLength | has_length] (#block4.5.6)\n        * [4.5.7. isNotEmpty | not_empty] (#block4.5.7)\n        * [4.5.8. startsWith | starts_with] (#block4.5.8)\n    * [4.6 isFileUpload | file_upload](#block4.6)\n        * [4.6.1. isBetween | between] (#block4.6.1)\n        * [4.6.2. isMimeType | mime_type] (#block4.6.2)\n        * [4.6.3. hasFileNameFormat | has_file_name_format] (#block4.6.3)\n        * [4.6.4. hasValidUploadDirectory | has_valid_upload_directory] (#block4.6.4)\n        * [4.6.5. notOverwritingExistingFile | not_overwriting_existing_file] (#block4.6.5)\n        * [4.6.6. hasLength | has_length] (#block4.6.6)\n        * [4.6.7. isImage | image] (#block4.6.7)\n* [4. Quality Code](#block4)\n* [5. Author](#block5)\n* [6. License](#block6)\n\n\u003ca name=\"block1\"\u003e\u003c/a\u003e\n# 1. Installation [↑](#index_block)\nThe recommended way to install the Input Validator is through [Composer](http://getcomposer.org). Run the following command to install it:\n\n```sh\nphp composer.phar require nilportugues/validator\n```\n\n\u003ca name=\"block2\"\u003e\u003c/a\u003e\n# 2. Usage [↑](#index_block)\n\nThe Validator interface is 100% human-friendly and readable. By default, it supports full validation and partial validation (stop when first error occurs).\n\n\u003ca name=\"block2.1\"\u003e\u003c/a\u003e\n### 2.1. Validation made for everyone [↑](#index_block)\n\nWhen writing validator input data it is expected to be match a set of rules. If one or more of these rules fail, a collection of errors is returned. This is the default behaviour for `validate($input)`.\n\nNilPortugues\\Validator supports up to 3 different styles to write validators: Instantiation, Factory or as a Class. Here's how you would validate an input `age` for these 3 styles:\n\n\u003ca name=\"block2.1.1\"\u003e\u003c/a\u003e\n#### 2.1.1. Instantiation of Validator class\n```php\nuse \\NilPortugues\\Validator\\Validator;\n\n$ageValidator = Validator::create()-\u003eisInteger('age');\n$result = $ageValidator-\u003eisPositive()-\u003eisBetween(18, 100, true)-\u003evalidate(28);\n$errors = $ageValidator-\u003egetErrors();\n```\n\n\u003ca name=\"block2.1.2\"\u003e\u003c/a\u003e\n#### 2.1.2. Factory using ValidatorFactory::create\n\nUsing the Validator as a factory will provide a Validator object each time the `::create` method is used.\n\nThis style fits best when validating lots of fields one after another or inside array loops where changing `$rules` dynamically can make sense.\n\n\n```php\nuse \\NilPortugues\\Validator\\ValidatorFactory;\n\n$rules = ['positive', 'between:18:100:true'];\n$ageValidator = ValidatorFactory::create('age', 'integer', $rules);\n\n$result = $ageValidator-\u003evalidate(28);\n$errors = $ageValidator-\u003egetErrors();\n```\n\n\u003ca name=\"block2.1.3\"\u003e\u003c/a\u003e\n#### 2.1.3. Extending from the BaseValidator\n\nValidators extending from `\\NilPortugues\\Validator\\BaseValidator` are short and maintainable.\n\n```php\nuse \\NilPortugues\\Validator\\BaseValidator;\n\nclass AgeValidator extends BaseValidator\n{\n    /**\n     * @var string\n     */\n    protected $type = 'integer';\n\n    /**\n     * @var array\n     */\n    protected $rules = [\n        'positive',\n        'between:18:100:true'\n    ];\n}\n\n$ageValidator = new AgeValidator();\n\n$result = $ageValidator-\u003evalidate('age', 28);\n$errors = $ageValidator-\u003egetErrors();\n```\n\nRules cannot be dynamically changed unless you provide the class a method to do so! For instance:\n\n```php\nuse \\NilPortugues\\Validator\\BaseValidator;\n\nclass AgeValidator extends BaseValidator\n{\n    /**\n     * @var string\n     */\n    protected $type = 'integer';\n\n    /**\n     * @var array\n     */\n    protected $rules = ['positive'];\n\n    /**\n     * @param array $rules\n     */\n    public function __construct(array $rules)\n    {\n        $this-\u003erules = array_merge($this-\u003erules, $rules);\n    }\n}\n\n$ageValidator = new AgeValidator(['between:18:100:true']);\n\n$result = $ageValidator-\u003evalidate('age', 28);\n$errors = $ageValidator-\u003egetErrors();\n```\n\n\u003ca name=\"block2.2\"\u003e\u003c/a\u003e\n### 2.2. Stop on first error [↑](#index_block)\n\nSometimes, fast validation checks are needed when validating input data. This is possible by passing `true` as the second argument to the `validate` method. \n\nFor instance, in the following code `isBetween`is never executed.\n\n```php\nuse \\NilPortugues\\Validator\\Validator;\n\n$age = Validator::create()-\u003eisInteger('age');\n$result = $age-\u003eisPositive()-\u003eisBetween(0, 100, true)-\u003evalidate(-10, true);\n```\n\u003ca name=\"block3\"\u003e\u003c/a\u003e\n# 3. Validation Message Translation [↑](#index_block)\n\nThe Input Validator features a default translation that can be found at `src/Errors/en_GB.php`. If no file path is provided when creating the validator instance, this file is used.\n\n---\n    Feel free to submit a pull request or open an issue with more translations!\n---\n\n#### Customization\nLanguage can be changed anytime by providing a file following the same structure.\n\n```php\n$translationFile = 'full/path/to/alternate-translation.php';\n\n$validator = Validator::create($translationFile);\n\n$stringValidator = $validator-\u003eisString('username');\n$errors = $stringValidator-\u003egetErrors(); //error array in the provided language.\n```\n\n#### Available translations\n\n- en_GB     **English (British)**\n\n\n\u003ca name=\"block4\"\u003e\u003c/a\u003e\n# 4. Methods [↑](#index_block)\n\nAll data type validators share 2 basic methods:\n\n- **isRequired**\n- **isNotNull**\n\nIts usage is fairly simple:\n\n```php\n$validator = Validator::create();\n\n$username = $validator-\u003eisString('username');\n\n$username-\u003eisRequired()-\u003evalidate('Nil'); //true\n$username-\u003eisNotNull()-\u003evalidate(''); //false\n\n//Or combined...\n$username-\u003eisRequired()-\u003eisNotNull()-\u003evalidate('Nil'); //true\n```\n\nFor optional data, wrap the validator function within an if with an `isset($value)` clause and validate using `isNotNull`.\n\nFor instance, suppose gender is a value from 0 to 2 (male, female, other) and is a non-mandatory value:\n\n```php\n$validator = Validator::create();\n\n$genderValue = $validator-\u003eisInteger('gender');\n$result = true;\n\nif (isset($gender)) {\n    $result = $genderValue-\u003eisNotNull()-\u003eisBetween(0, 2, true)-\u003evalidate($gender);\n}\n\nreturn $result;\n```\n\n\u003ca name=\"block4.1\"\u003e\u003c/a\u003e\n## 4.1 isString | string [↑](#index_block)\nString validation starts when creating a string field in the validator using the `isString` method.\n\n```php\n$username = Validator::create()-\u003eisString('username');\n```\nThe following chainable validation options are available for string data:\n\n#### 4.1.1. isAlphanumeric \u003ca name=\"block4.1.1\"\u003e\u003c/a\u003e [↑](#index_block)\n\n\u003ca name=\"block4.1.1.1\"\u003e\u003c/a\u003e\n##### 4.1.1.1 Instantiation of Validator class\n```php\nuse \\NilPortugues\\Validator\\Validator;\n\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisAlphanumeric()-\u003evalidate('28a'); // true\n$string-\u003eisAlphanumeric()-\u003evalidate('hello@example.com'); // false\n```\n\n\u003ca name=\"block4.1.1.2\"\u003e\u003c/a\u003e\n##### 4.1.1.2. Factory using Validator::create\n\n```php\nuse \\NilPortugues\\Validator\\Validator;\n\n$validator = Validator::create('propertyName', 'string', ['alphanumeric']);\n\n$validator-\u003evalidate('28a'); // true\n$validator-\u003evalidate('hello@example.com'); // false\n```\n\n\u003ca name=\"block4.1.1.3\"\u003e\u003c/a\u003e\n##### 4.1.1.3. Extending from the BaseValidator\n\n```php\nuse \\NilPortugues\\Validator\\BaseValidator;\n\nclass FieldValidator extends BaseValidator\n{\n    protected $type = 'string';\n\n    protected $rules = ['alphanumeric'];\n}\n\n$fieldValidator = new FieldValidator();\n\n$fieldValidator-\u003evalidate('propertyName', '28a'); //true\n$fieldValidator-\u003evalidate('propertyName', 'hello@example.com');\n```\n\n\n#### 4.1.2. isAlpha \u003ca name=\"block4.1.2\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisAlpha()-\u003evalidate('Hello World'); // true\n$string-\u003eisAlpha()-\u003evalidate('28a'); // false\n$string-\u003eisAlpha()-\u003evalidate('hello@example.com'); // false\n```\n\n#### 4.1.3. isBetween \u003ca name=\"block4.1.3\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisBetween(2, 4)-\u003evalidate('Nilo'); //false\n$string-\u003eisBetween(2, 4, true)-\u003evalidate('Nilo'); //true\n```\n\n#### 4.1.4. isCharset \u003ca name=\"block4.1.4\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisCharset(['UTF-8'])-\u003evalidate('Portugués'); //true\n```\n\n#### 4.1.5. isAllConsonants \u003ca name=\"block4.1.5\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisAllConsonants()-\u003evalidate('a'); //false\n$string-\u003eisAllConsonants()-\u003evalidate('bs'); //true\n```\n\n#### 4.1.6. contains \u003ca name=\"block4.1.6\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003econtains(123)-\u003evalidate('AAAAAAA123A'); //true\n$string-\u003econtains(123, true)-\u003evalidate('AAAAAAA123A'); //false\n```\n\n#### 4.1.7. isControlCharacters \u003ca name=\"block4.1.7\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisControlCharacters()-\u003evalidate(\"\\n\\t\"); //true\n$string-\u003eisControlCharacters()-\u003evalidate(\"\\nHello\\tWorld\"); //false\n```\n\n#### 4.1.8. isDigit \u003ca name=\"block4.1.8\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisDigit()-\u003evalidate('10'); //true\n\n$string-\u003eisDigit()-\u003evalidate('A'); //false\n$string-\u003eisDigit()-\u003evalidate(145.6); //false\n```\n\n#### 4.1.9. endsWith \u003ca name=\"block4.1.9\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eendsWith('aaaA')-\u003evalidate('AAAAAAAaaaA'); //true\n$string-\u003eendsWith(123, true)-\u003evalidate('AAAAAAA123'); //false\n```\n\n#### 4.1.10. equals \u003ca name=\"block4.1.10\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eequals('hello')-\u003evalidate('hello'); //true\n\n$string-\u003eequals(1)-\u003evalidate('1'); //true\n$string-\u003eequals(1, true)-\u003evalidate('1'); //false\n```\n\n#### 4.1.11. in \u003ca name=\"block4.1.11\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003ein('a12245 asdhsjasd 63-211', true)-\u003evalidate('5 asd'); //true\n$string-\u003ein(122, true)-\u003evalidate('a12245 asdhsjasd 63-211'); //false\n```\n\n#### 4.1.12. hasGraphicalCharsOnly \u003ca name=\"block4.1.12\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003ehasGraphicalCharsOnly()-\u003evalidate('arf12'); //true\n$string-\u003ehasGraphicalCharsOnly()-\u003evalidate(\"asdf\\n\\r\\t\"); //false\n```\n\n#### 4.1.13. hasLength \u003ca name=\"block4.1.13\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003ehasLength(5)-\u003evalidate('abcdefgh'); //false\n$string-\u003ehasLength(8)-\u003evalidate('abcdefgh'); //true\n```\n\n#### 4.1.14. isLowercase \u003ca name=\"block4.1.14\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisLowercase()-\u003evalidate('strtolower'); //true\n$string-\u003eisLowercase()-\u003evalidate('strtolOwer'); //false\n```\n\n#### 4.1.15. notEmpty \u003ca name=\"block4.1.15\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003enotEmpty()-\u003evalidate('a'); //true\n$string-\u003enotEmpty()-\u003evalidate(''); //false\n```\n\n#### 4.1.16. noWhitespace \u003ca name=\"block4.1.16\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003enoWhitespace()-\u003evalidate('aaaaa'); //true\n$string-\u003enoWhitespace()-\u003evalidate('lorem ipsum'); //false\n```\n\n#### 4.1.17. hasPrintableCharsOnly \u003ca name=\"block4.1.17\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003ehasPrintableCharsOnly()-\u003evalidate(\"LMKA0$%_123\"); //true\n$string-\u003ehasPrintableCharsOnly()-\u003evalidate(\"LMKA0$%\\t_123\"); //false\n```\n\n#### 4.1.18. isPunctuation \u003ca name=\"block4.1.18\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisPunctuation()-\u003evalidate('\u0026,.;'); //true\n$string-\u003eisPunctuation()-\u003evalidate('a'); //false\n```\n\n#### 4.1.19. matchesRegex \u003ca name=\"block4.1.19\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003ematchesRegex('/[a-z]/')-\u003evalidate('a'); //true\n$string-\u003ematchesRegex('/[a-z]/')-\u003evalidate('A'); //false\n```\n\n#### 4.1.20. isSlug \u003ca name=\"block4.1.20\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisSlug()-\u003evalidate('hello-world-yeah'); //true\n\n$string-\u003eisSlug()-\u003evalidate('-hello-world-yeah'); //false\n$string-\u003eisSlug()-\u003evalidate('hello-world-yeah-'); //false\n$string-\u003eisSlug()-\u003evalidate('hello-world----yeah'); //false\n```\n\n#### 4.1.21. isSpace \u003ca name=\"block4.1.21\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisSpace()-\u003evalidate('    '); //true\n$string-\u003eisSpace()-\u003evalidate('e e'); //false\n```\n\n#### 4.1.22. startsWith \u003ca name=\"block4.1.22\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003estartsWith('aaaA')-\u003evalidate('aaaAAAAAAAA'); //true\n$string-\u003estartsWith(123, true)-\u003evalidate('123AAAAAAA'); //false\n```\n\n#### 4.1.23. isUppercase \u003ca name=\"block4.1.23\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisUppercase()-\u003evalidate('AAAAAA'); //true\n$string-\u003eisUppercase()-\u003evalidate('aaaa'); //false\n```\n\n#### 4.1.24. isVersion \u003ca name=\"block4.1.24\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisVersion()-\u003evalidate('1.0.2'); //true\n$string-\u003eisVersion()-\u003evalidate('1.0.2-beta'); //true\n$string-\u003eisVersion()-\u003evalidate('1.0'); //true\n$string-\u003eisVersion()-\u003evalidate('1.0.2 beta'); //false\n```\n\n#### 4.1.25. isVowel \u003ca name=\"block4.1.25\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisVowel()-\u003evalidate('aeA'); //true\n$string-\u003eisVowel()-\u003evalidate('cds'); //false\n```\n\n#### 4.1.26. isHexDigit \u003ca name=\"block4.1.26\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisHexDigit()-\u003evalidate(100); //true\n$string-\u003eisHexDigit()-\u003evalidate('h0000'); //false\n```\n\n#### 4.1.27. hasLowercase \u003ca name=\"block4.1.27\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003ehasLowercase()-\u003evalidate('HELLOWOrLD'); //true\n$string-\u003ehasLowercase(3)-\u003evalidate('HeLLoWOrLD'); //true\n\n$string-\u003ehasLowercase()-\u003evalidate('HELLOWORLD'); //false\n$string-\u003ehasLowercase(3)-\u003evalidate('el'); //false\n```\n\n#### 4.1.28. hasUppercase \u003ca name=\"block4.1.28\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003ehasUppercase()-\u003evalidate('hello World'); //true\n$string-\u003ehasUppercase(2)-\u003evalidate('Hello World'); //true\n\n$string-\u003ehasUppercase()-\u003evalidate('hello world'); //false\n$string-\u003ehasUppercase(2)-\u003evalidate('helloWorld'); //false\n```\n\n#### 4.1.29. hasNumeric \u003ca name=\"block4.1.29\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003ehasNumeric()-\u003evalidate('hell0 W0rld'); //true\n$string-\u003ehasNumeric(3)-\u003evalidate('H3ll0 W0rld'); //true\n\n$string-\u003ehasNumeric()-\u003evalidate('hello world'); //false\n$string-\u003ehasNumeric(2)-\u003evalidate('h3lloWorld'); //false\n```\n\n#### 4.1.30. hasSpecialCharacters \u003ca name=\"block4.1.30\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003ehasSpecialCharacters()-\u003evalidate('hell0@W0rld'); //true\n$string-\u003ehasSpecialCharacters(2)-\u003evalidate('H3ll0@W0@rld'); //true\n\n$string-\u003ehasSpecialCharacters()-\u003evalidate('hello world'); //false\n$string-\u003ehasSpecialCharacters(2)-\u003evalidate('h3llo@World'); //false\n```\n\n#### 4.1.31. isEmail \u003ca name=\"block4.1.31\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisEmail()-\u003evalidate('hello@world.com'); //true\n$string-\u003eisEmail()-\u003evalidate('hello.earth@world.com'); //true\n$string-\u003eisEmail()-\u003evalidate('hello.earth+moon@world.com'); //true\n$string-\u003eisEmail()-\u003evalidate('hello@subdomain.world.com'); //true\n$string-\u003eisEmail()-\u003evalidate('hello.earth@subdomain.world.com'); //true\n$string-\u003eisEmail()-\u003evalidate('hello.earth+moon@subdomain.world.com'); //true\n$string-\u003eisEmail()-\u003evalidate('hello.earth+moon@127.0.0.1'); //true\n\n$string-\u003eisEmail()-\u003evalidate('hello.earth+moon@localhost'); //false\n```\n\n#### 4.1.32. isUrl \u003ca name=\"block4.1.32\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003e-\u003eisUrl()-\u003evalidate('http://google.com'); //true\n$string-\u003e-\u003eisUrl()-\u003evalidate('http://google.com/robots.txt'); //true\n$string-\u003e-\u003eisUrl()-\u003evalidate('https://google.com'); //true\n$string-\u003e-\u003eisUrl()-\u003evalidate('https://google.com/robots.txt'); //true\n$string-\u003e-\u003eisUrl()-\u003evalidate('//google.com'); //true\n$string-\u003e-\u003eisUrl()-\u003evalidate('//google.com/robots.txt'); //true\n```\n\n#### 4.1.33. isUUID($strict = true) \u003ca name=\"block4.1.33\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$string = Validator::create()-\u003eisString('propertyName');\n\n$string-\u003eisUUID()-\u003evalidate('6ba7b810-9dad-11d1-80b4-00c04fd430c8'); //true\n$string-\u003eisUUID()-\u003evalidate('6ba7b811-9dad-11d1-80b4-00c04fd430c8'); //true\n$string-\u003eisUUID()-\u003evalidate('6ba7b812-9dad-11d1-80b4-00c04fd430c8'); //true\n$string-\u003eisUUID()-\u003evalidate('6ba7b814-9dad-11d1-80b4-00c04fd430c8'); //true\n$string-\u003eisUUID()-\u003evalidate('00000000-0000-0000-0000-000000000000'); //true\n\n$string-\u003eisUUID(false)-\u003evalidate('6ba7b810-9dad-11d1-80b4-00c04fd430c8'); //true\n$string-\u003eisUUID(false)-\u003evalidate('6ba7b811-9dad-11d1-80b4-00c04fd430c8'); //true\n$string-\u003eisUUID(false)-\u003evalidate('6ba7b812-9dad-11d1-80b4-00c04fd430c8'); //true\n$string-\u003eisUUID(false)-\u003evalidate('6ba7b814-9dad-11d1-80b4-00c04fd430c8'); //true\n$string-\u003eisUUID(false)-\u003evalidate('00000000-0000-0000-0000-000000000000'); //true\n\n$string-\u003eisUUID()-\u003evalidate('{6ba7b810-9dad-11d1-80b4-00c04fd430c8}'); //false\n$string-\u003eisUUID()-\u003evalidate('216f-ff40-98d9-11e3-a5e2-0800-200c-9a66'); //false\n$string-\u003eisUUID()-\u003evalidate('{216fff40-98d9-11e3-a5e2-0800200c9a66}'); //false\n$string-\u003eisUUID()-\u003evalidate('216fff4098d911e3a5e20800200c9a66'); //false\n\n$string-\u003eisUUID(false)-\u003evalidate('{6ba7b810-9dad-11d1-80b4-00c04fd430c8}'); //true\n$string-\u003eisUUID(false)-\u003evalidate('216f-ff40-98d9-11e3-a5e2-0800-200c-9a66'); //true\n$string-\u003eisUUID(false)-\u003evalidate('{216fff40-98d9-11e3-a5e2-0800200c9a66}'); //true\n$string-\u003eisUUID(false)-\u003evalidate('216fff4098d911e3a5e20800200c9a66'); //true\n```\n\n\u003ca name=\"block4.2\"\u003e\u003c/a\u003e\n## 4.2 isInteger | integer and isFloat | float [↑](#index_block)\n\nNumber validation comes in two flavours, `Integers` and `Floats`. Both validators share the same method interface, but internal implementation is different.\n\nTo use these validators, do as follows:\n\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$float = $validator-\u003eisFloat('propertyName');\n```\n\n#### 4.2.1. isNotZero  \u003ca name=\"block4.2.1\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$integer-\u003eisNotZero()-\u003evalidate(1); //true\n$integer-\u003eisNotZero()-\u003evalidate(0); //false\n```\n\n#### 4.2.2. isPositive  \u003ca name=\"block4.2.2\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$integer-\u003eisPositive()-\u003evalidate(1); //true\n$integer-\u003eisPositive()-\u003evalidate(-10); //false\n$integer-\u003eisPositive()-\u003evalidate(0); //false\n```\n\n#### 4.2.3. isPositiveOrZero \u003ca name=\"block4.2.3\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$integer-\u003eisPositiveOrZero()-\u003evalidate(1); //true\n$integer-\u003eisPositiveOrZero()-\u003evalidate(-10); //false\n$integer-\u003eisPositiveOrZero()-\u003evalidate(0); //true\n```\n\n#### 4.2.4. isNegative  \u003ca name=\"block4.2.4\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$integer-\u003eisNegative()-\u003evalidate(-10); //true\n$integer-\u003eisNegative()-\u003evalidate(1); //false\n$integer-\u003eisNegative()-\u003evalidate(0); //false\n```\n\n#### 4.2.5. isNegativeOrZero \u003ca name=\"block4.2.5\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$integer-\u003eisNegativeOrZero()-\u003evalidate(-10); //true\n$integer-\u003eisNegativeOrZero()-\u003evalidate(1); //false\n$integer-\u003eisNegativeOrZero()-\u003evalidate(0); //true\n```\n\n#### 4.2.6. isBetween  \u003ca name=\"block4.2.6\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$integer-\u003eisBetween(10,20, false)-\u003evalidate(13); //true\n$integer-\u003eisBetween(10, 20, true)-\u003evalidate(10); //false\n```\n\n#### 4.2.7. isOdd  \u003ca name=\"block4.2.7\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$integer-\u003eisOdd()-\u003evalidate(3); //true\n$integer-\u003eisOdd()-\u003evalidate(2); //false\n```\n\n#### 4.2.8. isEven  \u003ca name=\"block4.2.8\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$integer-\u003eisEven()-\u003evalidate(2); //true\n$integer-\u003eisEven()-\u003evalidate(3); //false\n```\n\n#### 4.2.9. isMultiple  \u003ca name=\"block4.2.9\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$integer = Validator::create()-\u003eisInteger('propertyName');\n\n$integer-\u003eisMultiple(2)-\u003evalidate(4); //true\n$integer-\u003eisMultiple(2)-\u003evalidate(3); //false\n```\n\n\n\u003ca name=\"block4.3\"\u003e\u003c/a\u003e\n## 4.3 isObject | object [↑](#index_block)\n\n#### 4.3.1. isInstanceOf\u003ca name=\"block4.3.1\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$object = Validator::create()-\u003eisObject('propertyName');\n\n$object-\u003eisInstanceOf('DateTime')-\u003evalidate(new \\DateTime()); //true\n\n$object-\u003eisInstanceOf('DateTime')-\u003evalidate(new \\stdClass()); //false\n$object-\u003eisInstanceOf('DateTime')-\u003evalidate('a'); //false\n```\n\n#### 4.3.2. hasProperty\u003ca name=\"block4.3.2\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$object = Validator::create()-\u003eisObject('propertyName');\n\n$dummy = new Dummy();\n\n$object-\u003ehasProperty('userName')-\u003evalidate($dummy); //true\n$object-\u003ehasProperty('password')-\u003evalidate($dummy); //false\n```\n\n#### 4.3.3. hasMethod\u003ca name=\"block4.3.3\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$object = Validator::create()-\u003eisObject('propertyName');\n\n$dummy = new Dummy();\n\n$object-\u003ehasMethod('getUserName')-\u003evalidate($dummy); //true\n$object-\u003ehasMethod('getPassword')-\u003evalidate($dummy); //false\n```\n\n#### 4.3.4. hasParentClass\u003ca name=\"block4.3.4\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$object = Validator::create()-\u003eisObject('propertyName');\n\n$object-\u003ehasParentClass()-\u003evalidate(new Dummy()); //true\n$object-\u003ehasParentClass()-\u003evalidate(new \\stdClass()); //false\n```\n\n#### 4.3.5. isChildOf\u003ca name=\"block4.3.5\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$object = Validator::create()-\u003eisObject('propertyName');\n\n$dummy = new Dummy(); // class Dummy extends \\DateTime\n\n$object-\u003eisChildOf('DateTime')-\u003evalidate($dummy); //true\n$object-\u003eisChildOf('DateTimeZone')-\u003evalidate($dummy); //false\n```\n\n#### 4.3.6. inheritsFrom\u003ca name=\"block4.3.6\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$object = Validator::create()-\u003eisObject('propertyName');\n\n$dummy = new Dummy(); // class Dummy extends \\DateTime\n\n$object-\u003einheritsFrom('DateTime')-\u003evalidate($dummy); //true\n$object-\u003einheritsFrom('DateTimeZone')-\u003evalidate($dummy); //false\n```\n\n#### 4.3.7. hasInterface\u003ca name=\"block4.3.7\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$object = Validator::create()-\u003eisObject('propertyName');\n\n$object-\u003ehasInterface('Tests\\NilPortugues\\Validator\\Resources\\DummyInterface')-\u003evalidate($dummy); //true\n$object-\u003einheritsFrom('DateTimeZone')-\u003evalidate($dummy); //false\n```\n\n\n\u003ca name=\"block4.4\"\u003e\u003c/a\u003e\n## 4.4 isDateTime | date_time  [↑](#index_block)\nDateTime Validator accepts `\\DateTime` objects and `strings` variables representing **valid date formats**.\n\nAs you will see in the following examples, either two are allowed as parameters for any `date` value.\n\n#### 4.4.1. isAfter \u003ca name=\"block4.4.1\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n$date1 = '2014-01-01 00:00:00';\n$date2 = new \\DateTime($date1);\n\n$limit1 = '2013-12-31 23:59:59';\n\n$datetime-\u003eisAfter($limit1, false)-\u003evalidate($date1); // true\n$datetime-\u003eisAfter($limit1, false)-\u003evalidate($date2); // true\n\n$datetime-\u003eisAfter($date1, true)-\u003evalidate($date1); // true\n$datetime-\u003eisAfter($date2, true)-\u003evalidate($date2); // true\n\n$limit2 = '2015-01-01 00:00:00';\n\n$datetime-\u003eisAfter($limit2)-\u003evalidate($date1); // false\n$datetime-\u003eisAfter($limit2)-\u003evalidate($date2); // false\n```\n\n#### 4.4.2. isBefore \u003ca name=\"block4.4.2\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n$date1 = '2012-01-01 00:00:00';\n$date2 = new \\DateTime($date1);\n\n$limit1 = '2013-12-31 23:59:59';\n\n$datetime-\u003eisBefore($limit1, false)-\u003evalidate($date1); // true\n$datetime-\u003eisBefore($limit1, false)-\u003evalidate($date2); // true\n\n$datetime-\u003eisBefore($date1, true)-\u003evalidate($date1); // true\n$datetime-\u003eisBefore($date2, true)-\u003evalidate($date2); // true\n\n$limit2 = '2010-01-01 00:00:00';\n\n$datetime-\u003eisBefore($limit2)-\u003evalidate($date1); // false\n$datetime-\u003eisBefore($limit2)-\u003evalidate($date2); // false\n```\n\n#### 4.4.3. isBetween \u003ca name=\"block4.4.3\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n$date1 = '2014-01-01 00:00:00';\n$date2 = new \\DateTime($date1);\n\n$minDate = '2013-01-01 00:00:00';\n$maxDate = '2015-01-01 00:00:00';\n\n$datetime-\u003eisBetween($minDate, $maxDate, false)-\u003evalidate($date1); // true\n$datetime-\u003eisBetween($minDate, $maxDate, false)-\u003evalidate($date2); // true\n\n$datetime-\u003eisBetween($minDate, $maxDate, true)-\u003evalidate($date1); // true\n$datetime-\u003eisBetween($minDate, $maxDate, true)-\u003evalidate($date2); // true\n\n$minDate = '2013-12-01 00:00:00';\n$maxDate = '2013-12-30 00:00:00';\n\n$datetime-\u003eisBetween($minDate, $maxDate, false)-\u003evalidate($date1); // false\n$datetime-\u003eisBetween($minDate, $maxDate, true)-\u003evalidate($date1); // false\n```\n\n#### 4.4.4. isWeekend \u003ca name=\"block4.4.4\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$datetime-\u003eisWeekend()-\u003evalidate('2014-09-20'); // true\n$datetime-\u003eisWeekend()-\u003evalidate('2014-09-22'); // false\n```\n#### 4.4.5. isWeekday \u003ca name=\"block4.4.5\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$datetime-\u003eisWeekday()-\u003evalidate('2014-09-20'); // false\n$datetime-\u003eisWeekday()-\u003evalidate('2014-09-22'); // true\n```\n#### 4.4.6. isMonday \u003ca name=\"block4.4.6\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$datetime-\u003eisMonday()-\u003evalidate('2014-09-22'); // true\n```\n#### 4.4.7. isTuesday \u003ca name=\"block4.4.7\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$datetime-\u003eisTuesday()-\u003evalidate('2014-09-23'); // true\n```\n#### 4.4.8. isWednesday \u003ca name=\"block4.4.8\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$validator = Validator::create();\n$datetime = $validator-\u003eisDateTime('propertyName');\n\n$datetime-\u003eisWednesday()-\u003evalidate('2014-09-24'); // true\n```\n#### 4.4.9. isThursday \u003ca name=\"block4.4.9\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$datetime-\u003eisThursday()-\u003evalidate('2014-09-25'); // true\n```\n#### 4.4.10. isFriday \u003ca name=\"block4.4.10\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$datetime-\u003eisFriday()-\u003evalidate('2014-09-26'); // true\n```\n#### 4.4.11. isSaturday \u003ca name=\"block4.4.11\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$datetime-\u003eisSaturday()-\u003evalidate('2014-09-27'); // true\n```\n#### 4.4.12. isSunday \u003ca name=\"block4.4.12\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$datetime-\u003eisSunday()-\u003evalidate('2014-09-28'); // true\n```\n#### 4.4.13. isToday \u003ca name=\"block4.4.13\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$date = new \\DateTime('now');\n\n$datetime-\u003eisToday()-\u003evalidate($date); // true\n```\n#### 4.4.14. isYesterday \u003ca name=\"block4.4.14\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$date = new \\DateTime('now -1 day');\n\n$datetime-\u003eisYesterday()-\u003evalidate($date); // true\n```\n#### 4.4.15. isTomorrow \u003ca name=\"block4.4.15\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$date = new \\DateTime('now +1 day');\n\n$datetime-\u003eisTomorrow()-\u003evalidate($date); // true\n```\n#### 4.4.16. isLeapYear \u003ca name=\"block4.4.16\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n\n$date = new \\DateTime('2016-01-01');\n\n$datetime-\u003eisLeapYear()-\u003evalidate($date); // true\n```\n\n#### 4.4.17. isMorning \u003ca name=\"block4.4.17\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n```\n\n#### 4.4.18. isAftenoon \u003ca name=\"block4.4.18\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n```\n\n#### 4.4.19. isEvening \u003ca name=\"block4.4.19\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n```\n\n#### 4.4.20. isNight \u003ca name=\"block4.4.20\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n\n```php\n$datetime = Validator::create()-\u003eisDateTime('propertyName');\n```\n\n\u003ca name=\"block4.5\"\u003e\u003c/a\u003e\n## 4.5 isArray | array [↑](#index_block)\nCollections are data structures that hold other data structures or same type variables.\n\nSupported PHP data structures for the Collection validator are:\n\n- array\n- ArrayObject\n- SplFixedArray\n\n#### 4.5.1. each \u003ca name=\"block4.5.1\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$validator = Validator::create();\n$collection = $validator-\u003eisArray('propertyName');\n\n$valueIsString = $validator-\u003eisString('value')-\u003eisAlpha();\n$keyIsInteger = $validator-\u003eisInteger('key')-\u003eisPositive();\n\n$array = ['hello','world'];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray($array);\n\n$collection-\u003eeach($valueIsString)-\u003evalidate($array); //true\n$collection-\u003eeach($valueIsString, $keyIsInteger)-\u003evalidate($array); //true\n\n$collection-\u003eeach($valueIsString)-\u003evalidate($arrayObject); //true\n$collection-\u003eeach($valueIsString, $keyIsInteger)-\u003evalidate($arrayObject); //true\n\n$collection-\u003eeach($valueIsString)-\u003evalidate($fixedArray); //true\n$collection-\u003eeach($valueIsString, $keyIsInteger)-\u003evalidate($fixedArray); //true\n```\n\n#### 4.5.2. hasKeyFormat \u003ca name=\"block4.5.2\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$validator = Validator::create();\n$collection = $validator-\u003eisArray('propertyName');\n\n$array = ['one' =\u003e 'hello', 'two' =\u003e 'world'];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray(array_values($array));\n\n$keyIsString = $validator-\u003eisString('key')-\u003eisAlpha();\n$keyIsInteger = $validator-\u003eisInteger('key')-\u003eisPositive();\n\n$collection-\u003ehasKeyFormat($keyIsString)-\u003evalidate($array); //true\n$collection-\u003ehasKeyFormat($keyIsString)-\u003evalidate($arrayObject); //true\n$collection-\u003ehasKeyFormat($keyIsInteger)-\u003evalidate($fixedArray); //true\n\n```\n\n#### 4.5.3. endsWith \u003ca name=\"block4.5.3\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$collection = Validator::create()-\u003eisArray('propertyName');\n\n$array = ['one' =\u003e 'hello', 'two' =\u003e 1];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray(array_values($array));\n\n$collection-\u003eendsWith('1')-\u003evalidate($array); //true\n$collection-\u003eendsWith('1')-\u003evalidate($arrayObject); //true\n$collection-\u003eendsWith('1')-\u003evalidate($fixedArray); //true\n\n$collection-\u003eendsWith('1', true)-\u003evalidate($array); //false\n$collection-\u003eendsWith('1', true)-\u003evalidate($arrayObject); //false\n$collection-\u003eendsWith('1', true)-\u003evalidate($fixedArray); //false\n\n```\n\n#### 4.5.4. contains \u003ca name=\"block4.5.4\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$collection = Validator::create()-\u003eisArray('propertyName');\n\n$array = ['one' =\u003e 'hello', 'two' =\u003e 1];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray(array_values($array));\n\n$collection-\u003econtains('hello')-\u003evalidate($array); //true\n$collection-\u003econtains('hello')-\u003evalidate($arrayObject); //true\n$collection-\u003econtains('hello')-\u003evalidate($fixedArray); //true\n\n$collection-\u003econtains(1, true)-\u003evalidate($array); //true\n$collection-\u003econtains(1, true)-\u003evalidate($arrayObject); //true\n$collection-\u003econtains(1, true)-\u003evalidate($fixedArray); //true\n\n```\n\n#### 4.5.5. hasKey \u003ca name=\"block4.5.5\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$collection = Validator::create()-\u003eisArray('propertyName');\n\n$array = ['one' =\u003e 'hello', 'two' =\u003e 1];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray(array_values($array));\n\n$collection-\u003ehasKey('one')-\u003evalidate($array)); //true\n$collection-\u003ehasKey('one')-\u003evalidate($arrayObject)); //true\n$collection-\u003ehasKey(0)-\u003evalidate($fixedArray)); //true\n\n$array = [];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray(array_values($array));\n\n$collection-\u003ehasKey(0)-\u003evalidate($array)); //false\n$collection-\u003ehasKey(0)-\u003evalidate($arrayObject)); //false\n$collection-\u003ehasKey(0)-\u003evalidate($fixedArray)); //false\n\n```\n\n#### 4.5.6. hasLength \u003ca name=\"block4.5.6\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$collection = Validator::create()-\u003eisArray('propertyName');\n\n$array = ['one' =\u003e 'hello', 'two' =\u003e 1];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray(array_values($array));\n\n$collection-\u003ehasLength(2)-\u003evalidate($array)); //true\n$collection-\u003ehasLength(2)-\u003evalidate($arrayObject)); //true\n$collection-\u003ehasLength(2)-\u003evalidate($fixedArray)); //true\n\n$array = [];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray(array_values($array));\n\n$collection-\u003ehasLength(0)-\u003evalidate($array)); //true\n$collection-\u003ehasLength(0)-\u003evalidate($arrayObject)); //true\n$collection-\u003ehasLength(0)-\u003evalidate($fixedArray)); //true\n\n```\n\n\n#### 4.5.7. isNotEmpty \u003ca name=\"block4.5.7\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$collection = Validator::create()-\u003eisArray('propertyName');\n\n$array = ['one' =\u003e 'hello', 'two' =\u003e 1];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray(array_values($array));\n\n$collection-\u003eisNotEmpty()-\u003evalidate($array)); //true\n$collection-\u003eisNotEmpty()-\u003evalidate($arrayObject)); //true\n$collection-\u003eisNotEmpty()-\u003evalidate($fixedArray)); //true\n\n$array = [];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray(array_values($array));\n\n$collection-\u003eisNotEmpty()-\u003evalidate($array)); //false\n$collection-\u003eisNotEmpty()-\u003evalidate($arrayObject)); //false\n$collection-\u003eisNotEmpty()-\u003evalidate($fixedArray)); //false\n```\n\n\n#### 4.5.8. startsWith \u003ca name=\"block4.5.8\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$collection = Validator::create()-\u003eisArray('propertyName');\n\n$array = [1, 2, 3];\n$arrayObject = new \\ArrayObject($array);\n$fixedArray = (new \\SplFixedArray())-\u003efromArray($array);\n\n$collection-\u003estartsWith(1)-\u003evalidate($array)); //true\n$collection-\u003estartsWith(1)-\u003evalidate($arrayObject)); //true\n$collection-\u003estartsWith(1)-\u003evalidate($fixedArray)); //true\n\n$collection-\u003estartsWith('1', true)-\u003evalidate($array)); //false\n$collection-\u003estartsWith('1', true)-\u003evalidate($arrayObject)); //false\n$collection-\u003estartsWith('1', true)-\u003evalidate($fixedArray)); //false\n```\n\n\n\u003ca name=\"block4.6\"\u003e\u003c/a\u003e\n## 4.6 isFileUpload | file_upload [↑](#index_block)\nFileUpload validation is one of the most boring parts of web development, but this validator makes things a breeze.\n\n### One file validation\nUsing FileUpload validator alone, you can validate single file uploads.\n\n```html\n\u003cform method=\"POST\" enctype=\"multipart/form-data\"\u003e\n  \u003cinput name=\"image\" type=\"file\" accept=\"image/*\"\u003e\n  \u003cinput type=\"submit\" value=\"Submit\"\u003e\n\u003c/form\u003e\n```\nOn the server side, validation is done as follows:\n\n```php\n$fileValidator = Validator::create()-\u003eisFileUpload('image');\n\n$fileValidator\n     -\u003eisBetween(0, 3, 'MB', true)\n     -\u003eisMimeType(['image/png', 'image/gif', 'image/jpeg'])\n     -\u003ehasValidUploadDirectory('./uploads/images')\n     -\u003enotOverwritingExistingFile('./uploads/images')\n     -\u003evalidate('image');\n```\n\n### Multiple file validation\n\nFor instance, let's say file upload is done using the following form:\n\n```html\n\u003cform method=\"POST\" enctype=\"multipart/form-data\"\u003e\n  \u003cinput type=\"file\" name=\"image[]\" multiple=\"multiple\" accept=\"image/*\"\u003e\n  \u003cinput type=\"submit\" value=\"Submit\"\u003e\n\u003c/form\u003e\n```\n\nOn the server side it is done exactly the same as before! Easy, right? :)\n\n\n#### 4.6.1. isBetween($minSize, $maxSize, $inclusive = false)  \u003ca name=\"block4.6.1\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$file = Validator::create()-\u003eisFileUpload('image');\n\n$file-\u003eisBetween(1, 3, 'MB', true)-\u003evalidate('image');\n```\n\n#### 4.6.2. isMimeType(array $allowedTypes)  \u003ca name=\"block4.6.2\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$file = Validator::create()-\u003eisFileUpload('image');\n\n$file-\u003eisMimeType(['image/png', 'image/gif', 'image/jpeg'])-\u003evalidate('image');\n```\n\n#### 4.6.3. hasFileNameFormat(AbstractValidator $validator)  \u003ca name=\"block4.6.3\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$validator = Validator::create();\n$file = $validator-\u003eisFileUpload('image');\n$stringValidator = $validator-\u003eisString('image')-\u003eisAlpha();\n\n$file-\u003ehasFileNameFormat($stringValidator)-\u003evalidate('image');\n```\n\n#### 4.6.4. hasValidUploadDirectory($uploadDir)  \u003ca name=\"block4.6.4\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$file = Validator::create()-\u003eisFileUpload('image');\n\n$file-\u003ehasValidUploadDirectory('./uploads/images')-\u003evalidate('image');\n```\n\n#### 4.6.5. notOverwritingExistingFile($uploadDir)  \u003ca name=\"block4.6.5\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$file = Validator::create()-\u003eisFileUpload('image');\n\n$file-\u003enotOverwritingExistingFile('./uploads/images')-\u003evalidate('image');\n```\n\n#### 4.6.6. hasLength($size)  \u003ca name=\"block4.6.6\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$file = Validator::create()-\u003eisFileUpload('image');\n\n$file-\u003ehasLength(1)-\u003evalidate('image');\n```\n\n#### 4.6.7. isImage()  \u003ca name=\"block4.6.7\"\u003e\u003c/a\u003e [↑](#index_block)\n\n##### Example\n```php\n$file = Validator::create()-\u003eisFileUpload('image');\n\n$file-\u003eisImage()-\u003evalidate('image');\n```\n\n\u003ca name=\"block4\"\u003e\u003c/a\u003e\n# 4. Quality Code [↑](#index_block)\nTesting has been done using PHPUnit and [Travis-CI](https://travis-ci.org). All code has been tested to be compatible from PHP 5.4 up to PHP 5.6 and [HHVM](http://hhvm.com/).\n\nTo run the test suite, you need [Composer](http://getcomposer.org):\n\n```bash\n    php composer.phar install --dev\n    php bin/phpunit\n```\n\n\u003ca name=\"block5\"\u003e\u003c/a\u003e\n# 5. Author [↑](#index_block)\nNil Portugués Calderó\n\n - \u003ccontact@nilportugues.com\u003e\n - [http://nilportugues.com](http://nilportugues.com)\n\n\n\u003ca name=\"block6\"\u003e\u003c/a\u003e\n# 6. License [↑](#index_block)\nThe Input Validator is licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilportugues%2Fphp-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnilportugues%2Fphp-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilportugues%2Fphp-validator/lists"}