This package offers extra validation rules for Laravel.
This package requires Laravel 11+ and PHP 8.2+. If you need to support older version, see the table below:
Version | Compatible with |
---|---|
6.0.0 | 11+ |
4.0.0+ | 10+ |
3.0.0 | 9+ |
1.4.0+ | 8+ |
1.2.0+ | 7+ |
1.1.0 | 6+ |
1.0.1 | 5.7+ |
You can install the package via composer:
composer require vdhicts/laravel-validation-rules
The package will automatically register itself in Laravel.
The package includes both English and Dutch translations. The translations can be published by running:
php artisan vendor:publish
Validates the provided BIC number.
'field' => [new \BicNumber()],
Validates if the value contains a certain phrase.
'field' => [new Contains($needle)],
Validates if the value contains any of the provided phrases.
'field' => [new ContainsAny(['foo', 'bar'])],
Validates if the value is a date after or equals the provided date (Carbon).
'field' => [new DateAfterOrEqual($date)],
Validates if the value is a date before or equals the provided date (Carbon).
'field' => [new DateBeforeOrEqual($date)],
Validates if the selected minutes for the provided date are according to the available minutes.
'field' => [new DateHasSpecificMinutes([0, 15, 30, 45])],
When the date is not according to the 'Y-m-d H:i' format then you are able to specify the format as second parameter:
'field' => [new DateHasSpecificMinutes([0, 15, 30, 45], 'd-m-Y H:i')],
Validates if the value is a valid dutch phone number. Both mobile or landlines are supported. See the Phone
validation
rule to validate a phone number which isn't limited to the Netherlands.
'field' => [new DutchPhone()],
Validates if the value is a valid dutch zip code, like 1234AB
.
'field' => [new DutchPostalCode()],
Validates if the value contains a valid hostname, like example.com
.
'field' => [new HostName()],
Validates if the value contains a valid IBAN.
'field' => [new InternationalBankAccountNumber()],
Validates if the value is an interval, i.e. PT30S
.
'field' => [new Interval()],
Validates if the value is differing less then the provided amount of hours.
'field' => [new MaximumHourDifference($start, 10)];
Validates if the value is a structural valid MIME.
'field' => [new MimeType()],
Validates if the value NOT contains a certain phrase.
'field' => [new NotContains($needle)],
Validates if the value is a valid phone number.
'field' => [new Phone()],
Validates if the value is an interval and the interval is positive.
'field' => [new PositiveInterval()],
Validates if the value is a valid price. The rule optionally accepts a specific decimal sign. When the decimal isn't
provided it accepts both ,
or .
signs.
'field' => [new Price()], // accepts both , and .
'field' => [new Price(',')], // accepts only ,
Validates if the value is a valid secure url, i.e. is a HTTPS url.
'field' => [new SecureUrl()],
Validates if the value is a valid version according to the Semver standard.
'field' => [new Semver()],
Validates if the value is a valid formatted VAT number.
'field' => [new VatNumber()],
Be aware: It doesn't check if the number is known in the VAT database. If you need to know the VAT number is truly legit, check with VIES.
Any contribution is welcome, but it should be (unit) tested and meet the PSR-12 standard and please create one pull request per feature. In exchange, you will be credited as contributor on this page.
If you discover any security related issues in this or other packages of Vdhicts, please email [email protected] instead of using the issue tracker.
This package is open-sourced software licensed under the MIT license.
Vdhicts is the name of my personal company. Vdhicts develops and implements IT solutions for businesses and educational institutions.