Examples of Custom validation rules (16)

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: firefly-iii/firefly-iii (Github)
★ 8598 Created: Jun 2014 Updated: Aug 2022 Laravel version: 8
Files in the example:
- app/Rules/IsBoolean.php
- app/Api/V1/Requests/Models/Rule/StoreRequest.php
Repository: bytefury/crater (Github)
★ 6212 Created: Nov 2019 Updated: Aug 2022 Laravel version: 8
Files in the example:
- app/Rules/Backup/PathToZip.php
- app/Http/Controllers/V1/Backup/DownloadBackupController.php
Repository: pterodactyl/panel (Github)
★ 4072 Created: Dec 2016 Updated: Aug 2022 Laravel version: 8
Files in the example:
- app/Rules/Username.php
- app/Models/User.php
Repository: laravelio/laravel.io (Github)
★ 2186 Created: May 2016 Updated: Aug 2022 Laravel version: 8
Files in the example:
- app/Rules/PasscheckRule.php
- app/Http/Requests/UpdatePasswordRequest.php
Repository: HDInnovations/UNIT3D-Community-Edition (Github)
★ 1548 Created: Dec 2017 Updated: Aug 2022 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)
★ 1503 Created: Dec 2016 Updated: Jun 2022 Laravel version: 8
Files in the example:
- app/Rules/AlphaName.php
- app/Http/Requests/UsersRequest.php
Repository: spatie/spatie.be (Github)
★ 384 Created: Oct 2020 Updated: Aug 2022 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)
★ 316 Created: Aug 2018 Updated: Aug 2022 Laravel version: 8
Files in the example:
- app/Rules/StrAlphaUnderscore.php
- app/Http/Requests/StoreUrl.php
- app/Http/Controllers/UrlController.php
Repository: jcergolj/laravellte (Github)
★ 202 Created: Jan 2020 Updated: Jul 2022 Laravel version: 8
Files in the example:
- app/Rules/PasswordCheckRule.php
- app/Http/Livewire/Profile/UpdatePassword.php
Repository: LaraBug/larabug-app (Github)
★ 190 Created: Apr 2021 Updated: Jul 2022 Laravel version: 8
Files in the example:
- app/Rules/StartsWith.php
- app/Http/Requests/ProjectRequest.php
Repository: christophrumpel/larastreamers (Github)
★ 178 Created: May 2021 Updated: Jul 2022 Laravel version: 8
Files in the example:
- app/Rules/YouTubeRule.php
- app/Http/Livewire/SubmitYouTubeLiveStream.php
Repository: JustinByrne/Mealing (Github)
★ 73 Created: Oct 2020 Updated: May 2022 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)
★ 7 Created: May 2021 Updated: Feb 2022 Laravel version: 8
Files in the example:
- app/Rules/ExistingReservationRuleForInterval.php
- app/Http/Requests/ReservationCreateRequest.php
Repository: Ayenko4all/school-management-system-backend (Github)
★ 6 Created: Aug 2021 Updated: Nov 2021 Laravel version: 8
Files in the example:
- app/Rules/CreateClassroomRule.php
- app/Http/Requests/CreateClassroomRequest.php
Repository: RatulSaqibKhan/emoji-calculator-laravel (Github)
★ 1 Created: Sep 2021 Updated: Nov 2021 Laravel version: 8
Files in the example:
- app/Rules/OperandRule.php
- app/Http/Requests/CalculatorRequest.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

Additional resources on custom validation rules: