Skip to content

Commit c981e6a

Browse files
committed
Document remaining validation rules.
1 parent b90038b commit c981e6a

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

README.md

+114
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Latest Stable Version](https://poser.pugx.org/f9webltd/laravel-validation-rules/v)](https://packagist.org/packages/f9webltd/laravel-validation-rules)
12
[![Scrutinizer coverage (GitHub/BitBucket)](https://img.shields.io/scrutinizer/coverage/g/f9webltd/laravel-validation-rules)]()
23
[![Scrutinizer code quality (GitHub/Bitbucket)](https://img.shields.io/scrutinizer/quality/g/f9webltd/laravel-validation-rules)]()
34
[![Build Status](https://travis-ci.org/f9webltd/laravel-validation-rules.svg)](https://travis-ci.org/f9webltd/laravel-validation-rules)
@@ -52,6 +53,13 @@ Alternatively use the rule directly with a [Laravel form request object](https:/
5253
- [`HexColourCode`](#hexcolourcode)
5354
- [`Honorific`](#honorific)
5455
- [`IncludesHtml`](#includeshtml)
56+
- [`NoWhitespace`](#nowhitespace)
57+
- [`OddNumber`](#oddnumber)
58+
- [`StringContains`](#stringcontains)
59+
- [`StrongPassword`](#strongpassword)
60+
- [`TitleCase`](#titlecase)
61+
- [`UKMobilePhone`](#ukmobilephone)
62+
- [`Uppercase`](#uppercase)
5563

5664
### `Base64EncodedString`
5765

@@ -121,6 +129,112 @@ Ensure the passed attribute is a valid honorific, omitting appended dots. The li
121129

122130
Ensure the passed attribute contains HTML.
123131

132+
### `NoWhitespace`
133+
134+
Ensure the passed attribute contains no whitespace.
135+
136+
### `OddNumber`
137+
138+
Ensure the passed attribute is an odd number.
139+
140+
### `StringContains`
141+
142+
Ensure the given attribute contains the provided strings.
143+
144+
Minimum usage example to ensure the attribute in question contains the string `php` or `laravel`:
145+
146+
```php
147+
use F9Web\ValidationRules\Rules\StringContains;
148+
149+
// ...
150+
151+
$request->validate([
152+
'description' => [
153+
'required',
154+
(new StringContains())->phrases([
155+
'laravel',
156+
'php',
157+
]),
158+
],
159+
]);
160+
```
161+
162+
Optionally force the string to contain *all* provided phrases:
163+
164+
```php
165+
use F9Web\ValidationRules\Rules\StringContains;
166+
167+
// ...
168+
169+
$request->validate([
170+
'description' => [
171+
'required',
172+
(new StringContains())->phrases([
173+
'laravel',
174+
'php',
175+
])->strictly(),
176+
],
177+
]);
178+
```
179+
The validation message will include the list phrases based upon the provided configuration.
180+
181+
### `StrongPassword`
182+
183+
Ensure the given attribute matches the provided conditions.
184+
185+
Minimum usage example to ensure the attribute:
186+
187+
- is a minimum of eight characters in length
188+
- contains upper and lowercase characters
189+
- contains at least one number
190+
191+
```php
192+
use F9Web\ValidationRules\Rules\StrongPassword;
193+
194+
// ...
195+
196+
$request->validate([
197+
'password' => [
198+
'required',
199+
(new StrongPassword()),
200+
],
201+
]);
202+
```
203+
204+
Additional methods are available.
205+
206+
```php
207+
use F9Web\ValidationRules\Rules\StrongPassword;
208+
209+
// ...
210+
211+
$request->validate([
212+
'password' => [
213+
'required',
214+
(new StrongPassword())
215+
->forceUppercaseCharacters()
216+
->forceLowercaseCharacters(false)
217+
->forceNumbers()
218+
->forceSpecialCharacters()
219+
// ->withSpecialCharacters('£$*%^'),
220+
],
221+
]);
222+
```
223+
224+
The default special characters are `!@#$%^&*()\-_=+{};:,<."£~?|>`. Optionally the `withSpecialCharacters()` method can be used to define a custom list.
225+
226+
### `TitleCase`
227+
228+
Ensure the provided attribute is [title case](https://laravel.com/docs/7.x/helpers#method-title-case).
229+
230+
### `UKMobilePhone`
231+
232+
Ensure the provided attribute is a valid UK mobile telephone number.
233+
234+
### `Uppercase`
235+
236+
Ensure the provided attribute is entirely uppercase.
237+
124238
## Contribution
125239

126240
Any ideas are welcome. Feel free to submit any issues or pull requests.

src/Rules/StringContains.php

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ function ($phrase) use ($value) {
4242

4343
if ($this->mustContainAllPhrases) {
4444
return Str::containsAll($value, $this->phrases);
45-
// return $matched->count() === count($this->phrases);
4645
}
4746

4847
return $matched->isNotEmpty();

src/Rules/StrongPassword.php

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public function forceSpecialCharacters(bool $flag = true): self
134134
*/
135135
public function withSpecialCharacters(string $characters): self
136136
{
137+
$this->forceSpecialCharacters();
138+
137139
$this->specialCharacters = $characters;
138140

139141
return $this;

0 commit comments

Comments
 (0)