Laravel Extended Validation

A collection of useful validation rules for Laravel applications, available as rule classes, fluent Rule macros, and string rules.

A collection of useful validation rules for Laravel applications. Every rule works in three ways: as an invokable rule class, as a fluent Rule:: macro, and as a classic string rule.

composer require mrpunyapal/laravel-extended-validation

Quick start

Use any rule 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',
]);

Available rules

Rule Class Description Syntax
without_alias WithoutAlias Reject plus-addressed email aliases (e.g. 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

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). The goal was to help applications prevent trial abuse and duplicate account creation.

The pull request was closed because plus-addressing is technically 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 application 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 that inspired these rules.

Next steps