mrpunyapal / laravel-extended-validation
A collection of useful validation rules rejected from Laravel core, implemented the Laravel way.
Package info
github.com/MrPunyapal/laravel-extended-validation
pkg:composer/mrpunyapal/laravel-extended-validation
Requires
- php: ^8.3|^8.4|^8.5
- illuminate/contracts: ^11.0||^12.0||^13.0
- illuminate/support: ^11.0||^12.0||^13.0
- illuminate/validation: ^11.0||^12.0||^13.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.14
- mrpunyapal/docsmith: 0.5.1
- mrpunyapal/rector-pest: ^0.1.0
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^11.0||^10.0||^9.0
- pestphp/pest: ^3.0||^4.0
- pestphp/pest-plugin-arch: ^3.0||^4.0
- pestphp/pest-plugin-laravel: ^3.0||^4.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- rector/rector: ^2.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A collection of validation rules for Laravel applications. Every rule works in three ways: as an invokable rule class, as a fluent Rule:: macro, and as a standard string rule.
Quick start
Install the package via Composer:
composer require mrpunyapal/laravel-extended-validation
Use rules with class syntax, fluent macros, or pipe-delimited strings:
use Illuminate\Validation\Rule; use MrPunyapal\LaravelExtendedValidation\Rules\WithoutAlias; use MrPunyapal\LaravelExtendedValidation\Rules\NotEmail; use MrPunyapal\LaravelExtendedValidation\Rules\Slug; $request->validate([ 'email' => ['required', 'email', new WithoutAlias], 'username' => ['required', 'string', Rule::notEmail()], 'slug' => 'required|slug', ]);
Why this package exists
This package started when I submitted a pull request (PR #61522) to the Laravel framework to add a validation rule for rejecting plus-addressed email aliases (such as username+tag@gmail.com) to prevent trial abuse and duplicate account creation.
The pull request was closed because plus-addressing is valid per RFC 5322, and the Laravel core team prioritizes keeping built-in validation rules strictly aligned with RFC standards while keeping framework core lean.
That prompted a closer look at other validation pull requests closed across the framework repository over the years. Many addressed practical real-world needs (such as verifying slugs, SemVer strings, Luhn checksums, or word counts), but were kept out of core to prevent framework bloat. This package gathers those useful validation rules together in one place, built the Laravel way. See the Acknowledgements page for the complete list of community pull requests.
Available rules
| Rule | Class | Description | Syntax |
|---|---|---|---|
without_alias |
WithoutAlias |
Reject plus-addressed email aliases (user+tag@gmail.com) |
without_alias |
not_email |
NotEmail |
Ensure a value is not an email address | not_email |
slug |
Slug |
Validate clean URL slugs with configurable separator | slug / slug:_ |
even |
EvenNumber |
Ensure numeric input is an even integer | even |
odd |
OddNumber |
Ensure numeric input is an odd integer | odd |
semver |
Semver |
Validate Semantic Versioning 2.0.0 strings | semver |
base64_string |
Base64String |
Validate base64 strings and data URIs with optional MIME filters | base64_string |
luhn |
Luhn |
Validate numeric strings against the Luhn/MOD-10 checksum | luhn |
min_words |
MinWords |
Validate minimum word count | min_words:N |
max_words |
MaxWords |
Validate maximum word count | max_words:N |
domain |
Domain |
Validate domain names without requiring protocols | domain |
e164 |
E164Phone |
Validate international phone numbers in E.164 format | e164 |
isbn |
Isbn |
Validate ISBN-10, ISBN-13, or both with checksums | isbn / isbn:10 / isbn:13 |
country_code |
CountryCode |
Validate ISO 3166-1 country codes (alpha-2 or alpha-3) | country_code |
hex_color |
HexColor |
Validate CSS hex color codes (3, 4, 6, or 8 digits) | hex_color |
latitude |
Latitude |
Validate numeric coordinate between -90 and 90 degrees | latitude |
longitude |
Longitude |
Validate numeric coordinate between -180 and 180 degrees | longitude |
cidr |
Cidr |
Validate IPv4 or IPv6 CIDR subnet notations | cidr / cidr:v4 / cidr:v6 |
email_domain |
EmailDomain |
Validate email domain against allowed or blocked lists | email_domain |
not_hashed |
NotHashed |
Ensure string is not already a bcrypt/argon hashed password | not_hashed |
alpha_underscore |
AlphaUnderscore |
Ensure string contains only letters, numbers, and underscores | alpha_underscore |
unless_between |
UnlessBetween |
Ensure numeric value falls outside a specified range | unless_between:min,max |
without_whitespace |
WithoutWhitespace |
Ensure input does not contain any whitespace characters | without_whitespace |
no_html |
NoHtml |
Ensure input does not contain HTML tags | no_html |
url_protocol |
UrlProtocol |
Validate URL scheme against allowed protocols | url_protocol:https,sftp |
snake_case |
SnakeCase |
Validate strict snake_case string formatting | snake_case / snake_case:capital |
multiple_of |
MultipleOf |
Ensure numeric value is an exact multiple of a step | multiple_of:step |
alpha_num_ascii |
AlphaNumAscii |
Validate strict ASCII-only alphanumeric characters | alpha_num_ascii |
Three ways to use every rule
1. Class instance syntax (Recommended)
Direct instantiation provides full IDE autocomplete, type safety, and static analysis:
use MrPunyapal\LaravelExtendedValidation\Rules\WithoutAlias; use MrPunyapal\LaravelExtendedValidation\Rules\Slug; use MrPunyapal\LaravelExtendedValidation\Rules\MinWords; $request->validate([ 'email' => ['required', 'email', new WithoutAlias], 'slug' => ['required', new Slug('_')], 'bio' => ['required', new MinWords(50)], ]);
2. Fluent Rule macro syntax
All rules are available as camelCase macros on Illuminate\Validation\Rule:
use Illuminate\Validation\Rule; $request->validate([ 'email' => ['required', 'email', Rule::withoutAlias()], 'username' => ['required', 'string', Rule::notEmail()], 'slug' => ['required', Rule::slug()], 'phone' => ['required', Rule::e164()], 'country' => ['required', Rule::countryCode('alpha3')], ]);
3. String syntax
Use pipe-delimited string rules for concise form requests:
$request->validate([ 'email' => 'required|email|without_alias', 'username' => 'required|string|not_email', 'slug' => 'required|slug', 'phone' => 'required|e164', 'version' => 'required|semver', 'color' => 'required|hex_color', ]);
Configuration
Publish the configuration file to selectively enable or disable individual rules:
php artisan vendor:publish --tag="laravel-extended-validation-config"
Localization
Publish the translation files to customize error messages:
php artisan vendor:publish --tag="laravel-extended-validation-translations"
Laravel Boost
This package ships a Laravel Boost skill named laravel-extended-validation-development for on-demand AI guidance.
If your Laravel application uses Boost, discover the skill with:
php artisan boost:update --discover
Testing
composer test
Documentation
Full documentation is available at https://mrpunyapal.github.io/laravel-extended-validation.
Changelog
Please see CHANGELOG for more information on recent changes.
License
The MIT License (MIT). Please see License File for more information.