Examples of Custom validation rules (14)

Short information about custom validation rules

Sometimes the official Laravel validation rules are not enough, and you want to create something custom. It's pretty easy in Laravel, with php artisan make:rule command, and then you can use the generated class in the validation rules array.
Read more in the official Laravel docs.

Repository: bytefury/crater (Github)
★ 4133 Created: Nov 2019 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Rules/Backup/PathToZip.php
- app/Http/Controllers/V1/Backup/DownloadBackupController.php
Repository: pterodactyl/panel (Github)
★ 2612 Created: Dec 2016 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Rules/Username.php
- app/Models/User.php
Repository: laravelio/laravel.io (Github)
★ 1889 Created: May 2016 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Rules/PasscheckRule.php
- app/Http/Requests/UpdatePasswordRequest.php
Repository: HDInnovations/UNIT3D-Community-Edition (Github)
★ 1366 Created: Dec 2017 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Validators/EmailBlacklistValidator.php
- app/Providers/EmailBlacklistServiceProvider.php
- config/email-blacklist.php
- app/Http/Controllers/Auth/ApplicationController.php
- app/Helpers/EmailBlacklistUpdater.php
- config/app.php
Repository: guillaumebriday/laravel-blog (Github)
★ 1317 Created: Dec 2016 Updated: May 2021 Laravel version: 8
Files in the example:
- app/Rules/AlphaName.php
- app/Http/Requests/UsersRequest.php
Repository: spatie/spatie.be (Github)
★ 306 Created: Oct 2020 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Rules/MatchingLicense.php
- app/Http/Api/Requests/Activations/ShowActivationRequest.php
- resources/views/components/field.blade.php
Repository: realodix/urlhub (Github)
★ 242 Created: Aug 2018 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Rules/StrAlphaUnderscore.php
- app/Http/Requests/StoreUrl.php
- app/Http/Controllers/UrlController.php
Repository: LaraBug/larabug-app (Github)
★ 125 Created: Apr 2021 Updated: Jun 2021 Laravel version: 8
Files in the example:
- app/Rules/StartsWith.php
- app/Http/Requests/ProjectRequest.php
Repository: jcergolj/laravellte (Github)
★ 122 Created: Jan 2020 Updated: Jun 2021 Laravel version: 8
Files in the example:
- app/Rules/PasswordCheckRule.php
- app/Http/Livewire/Profile/UpdatePassword.php
Repository: christophrumpel/larastreamers (Github)
★ 82 Created: May 2021 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Rules/YouTubeRule.php
- app/Http/Livewire/SubmitYouTubeLiveStream.php
Repository: JustinByrne/Mealing (Github)
★ 42 Created: Oct 2020 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Rules/CurrentPasswordRule.php
- app/Http/Requests/ChangePasswordRequest.php
- app/Http/Controllers/ProfileController.php
Repository: Melcus/parking-system (Github)
★ 1 Created: May 2021 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Rules/ExistingReservationRuleForInterval.php
- app/Http/Requests/ReservationCreateRequest.php
Repository: SomeRandomGhUser/shekelcount (Github)
Created: Jul 2021 Updated: Jul 2021 Laravel version: 8
Files in the example:
- app/Rules/BelongsToUserRule.php
- app/Http/Requests/Categories/DeleteCategoryRequest.php
Repository: RatulSaqibKhan/emoji-calculator-laravel (Github)
Created: Sep 2021 Updated: Sep 2021 Laravel version: 8
Files in the example:
- app/Rules/OperandRule.php
- app/Http/Requests/CalculatorRequest.php

Additional resources on custom validation rules: