Complete List of Custom Validation Rules Provided by laravel-validate
The milwad-dev/laravel-validate package ships 41 custom validation rule classes located in src/Rules, automatically registering them as Laravel validator rules (e.g., valid_uuid, valid_iban) when the using_container configuration option is enabled.
The milwad-dev/laravel-validate package extends Laravel's validation capabilities with specialized rules for international formats, Persian-specific data, and modern web standards. This comprehensive collection of custom validation rules provided by laravel-validate covers everything from financial identifiers like IBANs and credit cards to text casing conventions and cryptographic tokens.
How laravel-validate Registers Custom Rules
The package's service provider handles automatic discovery and registration of validation rules. In src/LaravelValidateServiceProvider.php, the boot method (lines 75-89) iterates over every PHP file in the src/Rules directory using File::files(__DIR__.'/Rules').
When the using_container option in config/laravel-validate.php is set to true, each rule class is registered with Laravel's validator using the snake_case version of the filename as the rule name. For example, ValidUuid.php becomes the valid_uuid rule accessible in validation strings.
Complete Catalogue of Validation Rules
The package organizes 41 distinct validators into logical categories based on their validation domain.
Identity and Financial Identifiers
These rules validate standardized codes used in banking, telecommunications, and government ID systems:
- ValidUuid (
valid_uuid) – Validates UUID v4 strings using regex patterns insrc/Rules/ValidUuid.php - ValidUlid (
valid_ulid) – Checks Universally Unique Lexicographically Sortable Identifier format - ValidImei (
valid_imei) – Validates International Mobile Equipment Identity numbers - ValidIban (
valid_iban) – Verifies International Bank Account Numbers using checksum validation - ValidCreditCard (
valid_credit_card) – Implements the Luhn algorithm to validate credit card numbers - ValidVatId (
valid_vatid) – Checks syntactically correct European VAT identifiers - ValidNationalCard (
valid_national_card) – Validates national ID numbers for supported countries - ValidCartNumberIran (
valid_cart_number_iran) – Specific validation for Iranian bank card numbers - ValidIranPostalCode (
valid_iran_postal_code) – Validates 10-digit Iranian postal codes - ValidUsername (
valid_username) – Enforces username patterns allowing letters, numbers, underscores, and dashes - ValidDiscordUsername (
valid_discord_username) – Checks Discord'susername#1234format
Network and Web Standards
Rules for validating internet infrastructure and web-related formats:
-
ValidIpAddressIPV4 (
valid_ip_address_ipv4) – Validates IPv4 address format insrc/Rules/ValidIpAddressIPV4.php -
ValidIpAddressIPV6 (
valid_ip_address_ipv6) – Validates IPv6 address format -
ValidUrl (
valid_url) – Uses Laravel's URL validator with additional strictness checks -
ValidDomain (
valid_domain) – Validates DNS domain name syntax -
ValidPort (
valid_port) – Confirms numeric values fall within valid TCP/UDP port range (0-65535) -
ValidJwt (
valid_jwt) – Verifies JSON Web Token structure (three base64url-encoded parts separated by dots) -
ValidHtmlTag (
valid_html_tag) – Ensures strings are properly formed HTML tags -
ValidHashtag (
valid_hashtag) – Validates strings starting with # followed by alphanumerics/underscores -
ValidBitcoinAddress (
valid_bitcoin_address) – Checks Bitcoin wallet address format -
ValidSlug (
valid_slug) – Validates URL-friendly slugs (lowercase alphanumerics and dashes)
Text Formatting and Naming Conventions
Enforce consistent code and content formatting:
- ValidCamelCase (
valid_camel_case) – Validates camelCase strings insrc/Rules/ValidCamelCase.php - ValidPascalCase (
valid_pascal_case) – Checks for PascalCase formatting - ValidSnakeCase (
valid_snake_case) – Ensures snake_case naming conventions - ValidKebabCase (
valid_kebab_case) – Enforces kebab-case formatting - ValidCapitalCharWithNumber (
valid_capital_char_with_number) – Requires at least one uppercase letter and one digit - ValidDuplicateCharacter (
valid_duplicate_character) – Detects repeated characters within strings - ValidDuplicate (
valid_duplicate) – Identifies duplicated substrings - ValidSlashEndOfString (
valid_slash_end_of_string) – Requires trailing slashes at string endings
Location and Communication
Country-specific and contact information validators:
- ValidPhoneNumber (
valid_phone_number) – Validates phone numbers using configurable country-specific regex patterns defined inconfig/laravel-validate.php - ValidLandlineNumber (
valid_landline_number) – Validates landline numbers per country configuration - ValidCountry (
valid_country) – Validates that a country code exists in the supplied whitelist - ValidCarNumber (
valid_car_number) – Checks vehicle registration plate patterns for supported countries - ValidJalaliDate (
valid_jalali_date) – Validates dates in the Persian (Jalali) calendar system - ValidNameDaysWeek (
valid_name_days_week) – Validates weekday name strings
Numeric and Pattern Validators
Mathematical and custom pattern validation:
- ValidEvenNumber (
valid_even_number) – Ensures numeric values are even - ValidOddNumber (
valid_odd_number) – Ensures numeric values are odd - ValidPattern (
valid_pattern) – Allows arbitrary regex validation via rule parameters (e.g.,valid_pattern:/^[A-Z]{3}\d{4}$/) - ValidHexColor (
valid_hex_color) – Validates 3-digit or 6-digit hexadecimal color codes
Security and Encoding
Cryptographic and data encoding validators:
- ValidStrongPassword (
valid_strong_password) – Enforces passwords containing mixed case, digits, symbols, and minimum length requirements - ValidBase64 (
valid_base64) – Verifies that strings are correctly Base64-encoded
Usage Examples
Using Rule Objects Directly
You can instantiate rule classes directly without enabling container registration:
use Milwad\LaravelValidate\Rules\ValidUuid;
use Milwad\LaravelValidate\Rules\ValidStrongPassword;
$request->validate([
'order_id' => ['required', new ValidUuid],
'password' => ['required', new ValidStrongPassword],
]);
Using String-Based Rule Names
Enable automatic registration in config/laravel-validate.php:
return [
'using_container' => true,
];
Then use snake_case rule names in validation strings:
$request->validate([
'order_id' => 'required|valid_uuid',
'username' => 'required|valid_username',
'iban' => 'required|valid_iban',
'slug' => 'required|valid_slug',
]);
Passing Parameters to Rules
Some rules accept parameters, such as valid_pattern and valid_phone_number:
// Custom regex pattern
$request->validate([
'sku' => 'required|valid_pattern:/^[A-Z]{3}\d{4}$/',
]);
// Country-specific phone validation
$request->validate([
'mobile' => 'required|valid_phone_number:IR',
]);
Configure country-specific patterns in config/laravel-validate.php:
return [
'phone-country' => [
'IR' => ['regex' => '/^09\d{9}$/'], // Iran mobile numbers
'US' => ['regex' => '/^\+1\d{10}$/'],
],
];
Configuration and Localization
The package stores configuration in config/laravel-validate.php, allowing you to toggle the container-based registration via the using_container boolean. Translation files reside in lang/*/validate.php, providing localized error messages for each rule (e.g., __('validate.uuid')).
Key files in the repository structure:
src/LaravelValidateServiceProvider.php– Handles rule registration and container bindingsrc/Rules/*.php– Individual rule implementations (41 files total)config/laravel-validate.php– Configuration for container registration and country-specific validatorslang/en/validate.php– English language strings for validation messagestests/Rules/*Test.php– Comprehensive test suite for each rule
Summary
- 41 custom validation rules are available in the
src/Rulesdirectory, covering financial IDs, network addresses, text formats, and Persian-specific data - Automatic registration occurs via
LaravelValidateServiceProvider.phpwhenusing_containeris enabled, exposing snake_case rule names - Flexible usage supports both direct object instantiation and string-based validation rules
- Configurable validation allows country-specific phone and landline patterns through the configuration file
- Localization support is built-in via translation files for multilingual error messages
Frequently Asked Questions
How do I enable the string-based rule names like valid_uuid?
Set the using_container configuration option to true in config/laravel-validate.php. This triggers the service provider to automatically register all classes in src/Rules as Laravel validator rules using their snake_case filenames.
Can I use these rules without registering them in the container?
Yes. You can instantiate any rule class directly from the Milwad\LaravelValidate\Rules namespace and pass it as an object in your validation array, regardless of the using_container setting.
Does laravel-validate support localized error messages?
Yes. The package includes translation files in lang/*/validate.php. Each rule references translation keys (e.g., validate.uuid, validate.iban) that you can customize for different languages.
Which rules support parameter passing?
The ValidPattern rule accepts a regex parameter (valid_pattern:/regex/). ValidPhoneNumber accepts a country code parameter (valid_phone_number:IR) that maps to configurations in the config file. Most other rules operate without additional parameters.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →