Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 3abee54

Browse files
committed
docs: improved examples
1 parent 2db6382 commit 3abee54

10 files changed

+26
-34
lines changed

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66

77
PHP validator with expressive error messages.
88

9-
> [!NOTE]
10-
> This library is not in version 1.x mainly because there are few available rules.
11-
> Hopefully, that will change in the near future.
12-
13-
> [!IMPORTANT]
14-
> Expect some breaking changes until version `1.0`.
15-
169
## Requirements
1710

1811
- PHP 8.1 or higher.

docs/03-rules_choice.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ Choice(
1818
## Basic Usage
1919

2020
```php
21-
// Single choice
21+
// single choice
2222
Validator::choice(['red', 'green', 'blue'])->validate('green'); // true
2323
Validator::choice(['red', 'green', 'blue'])->validate('yellow'); // false
2424

25-
// Multiple choices
25+
// multiple choices
2626
Validator::choice(['red', 'green', 'blue'], multiple: true)->validate(['red', 'blue']); // true;
2727
Validator::choice(['red', 'green', 'blue'], multiple: true)->validate(['red', 'yellow']); // false;
2828

29-
// Multiple with minimum number of choices
29+
// multiple with minimum number of choices
3030
Validator::choice(['red', 'green', 'blue'], multiple: true, min: 2)->validate(['red', 'blue']); // true
3131
Validator::choice(['red', 'green', 'blue'], multiple: true, min: 2)->validate(['red']); // false
3232

33-
// Multiple with maximum number of choices
33+
// multiple with maximum number of choices
3434
Validator::choice(['red', 'green', 'blue'], multiple: true, max: 2)->validate(['red', 'blue']); // true
3535
Validator::choice(['red', 'green', 'blue'], multiple: true, max: 2)->validate(['red', 'green', 'blue']); // false
3636

37-
// Multiple with minimum and maximum number of choices
37+
// multiple with minimum and maximum number of choices
3838
Validator::choice(['red', 'green', 'blue'], multiple: true, min: 2, max: 3)->validate(['red', 'blue']); // true
3939
Validator::choice(['red', 'green', 'blue'], multiple: true, min: 2, max: 3)->validate(['red']); // false
4040
```

docs/03-rules_collection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Validator::collection(fields: [
6767
'age' => 25
6868
]); // false ("name" is missing)
6969

70-
// but it is possible to use the Optional validation for optiona fields
70+
// but it is possible to use the Optional validation for optional fields
7171
Validator::collection(fields: [
7272
'name' => Validator::optional(
7373
Validator::notBlank()

docs/03-rules_country.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ Country(
1212
## Basic Usage
1313

1414
```php
15-
// Default alpha-2 code
16-
Validator::country()->validate('PT'); // true
17-
Validator::country(code: 'alpha-2')->validate('PT'); // true
15+
// default alpha-2 code
16+
Validator::country()->validate('pt'); // true
1817

19-
// Alpha-3 code
20-
Validator::country(code: 'alpha-3')->validate('PRT'); // true
18+
// alpha-3 code
19+
Validator::country(code: 'alpha-3')->validate('prt'); // true
2120
```
2221

2322
> [!NOTE]

docs/03-rules_each-key.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ EachKey(
1313

1414
```php
1515
Validator::eachKey(
16-
Validator::notBlank()->type('string')
16+
Validator::type('string')->notBlank()
1717
)->validate(['red' => '#f00', 'green' => '#0f0']); // true
1818

1919
Validator::eachKey(
20-
Validator::notBlank()->type('string')
20+
Validator::type('string')->notBlank()
2121
)->validate(['red' => '#f00', 1 => '#0f0']); // false
2222
```
2323

docs/03-rules_each-value.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ EachValue(
1313

1414
```php
1515
Validator::eachValue(
16-
Validator::notBlank()->greaterThan(1)->lessThan(10)
16+
Validator::type('int')->range(1, 10)
1717
)->validate([4, 5, 6]); // true
1818

1919
Validator::eachValue(
20-
Validator::notBlank()->greaterThan(1)->lessThan(10)
20+
Validator::type('int')->range(1, 10)
2121
)->validate([4, 5, 20]); // false
2222
```
2323

docs/03-rules_email.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Email(
1313
## Basic Usage
1414

1515
```php
16-
// html5 mode (default)
16+
// default html5 mode
1717
Validator::email()->validate('test@example.com'); // true
1818
Validator::email()->validate('test@example'); // false
1919

docs/03-rules_timezone.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ Timezone(
1313
## Basic Usage
1414

1515
```php
16-
// All timezone identifiers
16+
// all timezone identifiers
1717
Validator::timezone()->validate('Europe/Lisbon'); // true
1818

19-
// Restrict timezone identifiers to a specific geographical zone
19+
// restrict timezone identifiers to a specific geographical zone
2020
Validator::timezone(timezoneGroup: \DateTimeZone::EUROPE)->validate('Europe/Lisbon'); // true
2121
Validator::timezone(timezoneGroup: \DateTimeZone::AFRICA)->validate('Europe/Lisbon'); // false
22-
// Or multiple geographical zones
22+
// or multiple geographical zones
2323
Validator::timezone(timezoneGroup: \DateTimeZone::AFRICA | \DateTimeZone::EUROPE)->validate('Europe/Lisbon'); // true
2424

25-
// Restrict timezone identifiers to a specific country
25+
// restrict timezone identifiers to a specific country
2626
Validator::timezone(timezoneGroup: \DateTimeZone::PER_COUNTRY, countryCode: 'pt')->validate('Europe/Lisbon'); // true
2727
Validator::timezone(timezoneGroup: \DateTimeZone::PER_COUNTRY, countryCode: 'en')->validate('Europe/Lisbon'); // false
2828
```

docs/03-rules_type.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ Type(
1515
## Basic Usage
1616

1717
```php
18-
// Single type
18+
// single type
1919
Validator::type('string')->validate('green'); // true
2020
Validator::type('alphanumeric')->validate('gr33n'); // true
2121

22-
// Multiple types
23-
// Validates if value is of at least one of the provided types
22+
// multiple types
23+
// validates if value is of at least one of the provided types
2424
Validator::type(['alpha', 'numeric'])->validate('green'); // true (alpha)
2525
Validator::type(['alpha', 'numeric'])->validate('33'); // true (numeric)
2626
Validator::type(['alpha', 'numeric'])->validate('gr33n'); // false (not alpha nor numeric)
2727

28-
// Class or interface type
28+
// class or interface type
2929
Validator::type(\DateTime::class)->validate(new \DateTime()); // true
3030
Validator::type(\DateTimeInterface::class)->validate(new \DateTime()); // true
3131
```

docs/03-rules_url.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ Url(
1616
```php
1717
Validator::url()->validate('https://example.com'); // true
1818

19-
// Only allow the https protocol
19+
// only allow the https protocol
2020
Validator::url(protocols: ['https'])->validate('http://example.com'); // false
21-
// Or allow the ftp protocol too
21+
// or allow the ftp protocol too
2222
Validator::url(protocols: ['https', 'ftp'])->validate('ftp://example.com'); // true
2323

24-
// Allow relative protocol
24+
// allow relative protocol
2525
Validator::url()->validate('//example.com'); // false
2626
Validator::url(allowRelativeProtocol: true)->validate('//example.com'); // true
2727
Validator::url(allowRelativeProtocol: true)->validate('https://example.com'); // true

0 commit comments

Comments
 (0)