Skip to content

Commit 8b20d0a

Browse files
committed
Initial commit
1 parent f3936e1 commit 8b20d0a

File tree

6 files changed

+1219
-1
lines changed

6 files changed

+1219
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
vendor/
3+
composer.lock

README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,80 @@
1-
# PHP-Validation
1+
# PHP Validation
2+
A complete validation library written in PHP
3+
4+
## Installation
5+
Use the package manager [composer](https://getcomposer.org) to install the library
6+
```bash
7+
composer require riculum/php-validation
8+
```
9+
10+
## Validation
11+
You can use either `isValidate`, which returns true or false, or `validate`, which either throws an exception on error or returns the formatted input.
12+
13+
### Example for isValidate
14+
```php
15+
$isValid = Validator::isValidEmail('john.doe@example.com');
16+
var_dump($isValid); // true or false
17+
```
18+
19+
### Example for validate
20+
```php
21+
try {
22+
$formattedEmail = Validator::validateEmail('john.doe@example.com');
23+
} catch (InvalidValidationException $e) {
24+
echo $e->getMessage();
25+
}
26+
```
27+
28+
## Possible validation
29+
```php
30+
public static function isValidChar(?string $char, int $minLength = 1, int $maxLength = 50, bool $required = false, ?string $default = null): bool;
31+
public static function isValidCity(string $city, int $minLength = 1, int $maxLength = 50): bool;
32+
public static function isValidCountryCode(string $countryCode, string $set = 'alpha-2', $caseSensitive = false): bool;
33+
public static function isValidCurrencyCode(string $currencyCode, $caseSensitive = false): bool;
34+
public static function isValidDomain(string $domain, $caseSensitive = true): bool;
35+
public static function isValidEmail(string $email, $caseSensitive = true): bool;
36+
public static function isValidLanguageCode(string $languageCode, $caseSensitive = false): bool;
37+
public static function isValidName(string $name, int $minLength = 1, int $maxLength = 50): bool;
38+
public static function isValidPassword(string $password, int $minLength = 8, int $maxLength = 250, bool $mixUpperLow = true, bool $mixLetterNumber = true, bool $mixSpecialChar = true): bool;
39+
public static function isValidPhone(string $phone, string $countryCode = ""): bool;
40+
public static function isValidStreet(string $street, int $minLength = 1, int $maxLength = 100): bool;
41+
public static function isValidZip(string $zip, int $minLength = 1, int $maxLength = 4): bool;
42+
public static function isValidWebsite(?string $website, bool $required = false, ?string $default = null): bool;
43+
public static function isValidDate(?string $date, string $format = "yyyy-mm-dd", bool $required = false, ?string $default = null): bool;
44+
public static function isValidDecimal(?string $decimal, bool $required = false, ?string $default = null): bool;
45+
public static function isValidInt(?string $int, int $minLength = 1, int $maxLength = 11, bool $required = false, ?string $default = null): bool;
46+
public static function isValidIBAN(?string $iban, bool $required = false, ?string $default = null): bool;
47+
public static function isValidBESRID(?string $besrId, bool $required = false, ?string $default = null): bool;
48+
public static function isValidEnum(?string $enum, array $enums, bool $required = false, ?string $default = null): bool;
49+
50+
public static function validateCity(string $city, int $minLength = 1, int $maxLength = 50): ?string;
51+
public static function validateCountryCode(string $countryCode, string $set = 'alpha-2', $caseSensitive = false): ?string;
52+
public static function validateCurrencyCode(string $currencyCode, $caseSensitive = false): ?string;
53+
public static function validateDomain(string $domain, $caseSensitive = true): ?string;
54+
public static function validateEmail(string $email, $caseSensitive = true): ?string;
55+
public static function validateLanguageCode(string $languageCode, $caseSensitive = false): ?string;
56+
public static function validateName(string $name, int $minLength = 1, int $maxLength = 50): ?string;
57+
public static function validatePassword(string $password, int $minLength = 8, int $maxLength = 250, bool $mixUpperLow = true, bool $mixLetterNumber = true, bool $mixSpecialChar = true): ?string;
58+
public static function validatePhone(string $phone, string $countryCode = ""): ?string;
59+
public static function validateStreet(string $street, int $minLength = 1, int $maxLength = 100): ?string;
60+
public static function validateZip(string $zip, int $minLength = 1, int $maxLength = 4): ?string;
61+
public static function validateDate(?string $date, string $format = "yyyy-mm-dd", bool $required = false, ?string $default = null): ?string;
62+
public static function validateDecimal(?string $decimal, bool $required = false, ?string $default = null): ?float;
63+
public static function validateInt(?string $int, int $minLength = 1, int $maxLength = 11, bool $required = false, ?string $default = null): ?int;
64+
public static function validateIBAN(?string $iban, bool $required = false, ?string $default = null): ?string;
65+
public static function validateBESRID(?string $besrId, bool $required = false, ?string $default = null): ?string;
66+
public static function validateEnum(?string $enum, array $enums, bool $required = false, ?string $default = null): ?string;
67+
public static function validateChar(?string $char, int $minLength, int $maxLength, bool $required, ?string $default): ?string;
68+
```
69+
70+
## Bugreport & Contribution
71+
If you find a bug, please either create a ticket in github, or initiate a pull request
72+
73+
## Versioning
74+
We adhere to semantic (major.minor.patch) versioning (https://semver.org/). This means that:
75+
76+
* Patch (x.x.patch) versions fix bugs
77+
* Minor (x.minor.x) versions introduce new, backwards compatible features or improve existing code.
78+
* Major (major.x.x) versions introduce radical changes which are not backwards compatible.
79+
80+
In your automation or procedure you can always safely update patch & minor versions without the risk of your application failing.

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "riculum/php-validation",
3+
"description": "A complete validation library written in PHP",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Riculum",
9+
"email": "riculum@outlook.com"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"Validation\\": "./"
15+
}
16+
},
17+
"require": {
18+
"php": ">=7.4.0",
19+
"ext-json": "*"
20+
}
21+
}

0 commit comments

Comments
 (0)