|
| 1 | +[](https://packagist.org/packages/f9webltd/laravel-validation-rules) |
1 | 2 | []()
|
2 | 3 | []()
|
3 | 4 | [](https://travis-ci.org/f9webltd/laravel-validation-rules)
|
@@ -52,6 +53,13 @@ Alternatively use the rule directly with a [Laravel form request object](https:/
|
52 | 53 | - [`HexColourCode`](#hexcolourcode)
|
53 | 54 | - [`Honorific`](#honorific)
|
54 | 55 | - [`IncludesHtml`](#includeshtml)
|
| 56 | +- [`NoWhitespace`](#nowhitespace) |
| 57 | +- [`OddNumber`](#oddnumber) |
| 58 | +- [`StringContains`](#stringcontains) |
| 59 | +- [`StrongPassword`](#strongpassword) |
| 60 | +- [`TitleCase`](#titlecase) |
| 61 | +- [`UKMobilePhone`](#ukmobilephone) |
| 62 | +- [`Uppercase`](#uppercase) |
55 | 63 |
|
56 | 64 | ### `Base64EncodedString`
|
57 | 65 |
|
@@ -121,6 +129,112 @@ Ensure the passed attribute is a valid honorific, omitting appended dots. The li
|
121 | 129 |
|
122 | 130 | Ensure the passed attribute contains HTML.
|
123 | 131 |
|
| 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 | + |
124 | 238 | ## Contribution
|
125 | 239 |
|
126 | 240 | Any ideas are welcome. Feel free to submit any issues or pull requests.
|
|
0 commit comments