Download the PHP package lloaldo/laravel-validate-spa without Composer
On this page you can find all versions of the php package lloaldo/laravel-validate-spa. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lloaldo/laravel-validate-spa
More information about lloaldo/laravel-validate-spa
Files in lloaldo/laravel-validate-spa
Package laravel-validate-spa
Short Description Spanish Custom Validation Package for Laravel CIF, NIF, NIE, NSS, IBAN, Postal Code, Phone numbers, License plate...
License MIT
Informations about the package laravel-validate-spa
Laravel Validate SPA
A Laravel package that provides custom validation rules for Spanish identification numbers: NIF, NIE, CIF, SSN, IBAN, POSTAL CODE, PHONE, LICENSE PLATE, CCC, PASSPORT .
Features
- Validates Spanish NIF (Documento Identificación Fiscal) and NIE (Número de Identidad de Extranjero).
- Validates Spanish CIF (Código de Identificación Fiscal).
- Validates Spanish SSN (Social Security Number).
- Validates Spanish IBAN (International Bank Account Number).
- Validates Postal Code Spanish.
- Validates Phone Number Spanish.
- Validates Spanish License plate vehicle(Vehículos Matrícula Española).
- Validates Spanish CCC(Old Spanish Bank Account, precursor of the IBAN).
- Validates Spanish Passport.
- Includes translatable error messages.
- Easy integration with Laravel's validation system.
Requirements
- PHP >= 8.0
- Laravel >= 9.0
Installation
-
Install the package via Composer
Run the following command in your Laravel project directory: -
Publish the language files (optional)
If you want to customize the validation error messages, publish the language files:This will copy the translation files to
resources/lang/vendor/laravel-validate-spa. You can modify the messages in your desired language (e.g.,es/validation.phpfor Spanish). - Service Provider (optional for Laravel 9+)
The package uses Laravel's auto-discovery feature, so no manual registration is needed. If you're using an older version of Laravel without package discovery, add the service provider toconfig/app.php:
Usage
Validation Rules
This package provides two custom validation rules: personal_id, tax_identifier, spanish_nif, spanish_nie, spanish_cif, spanish_ssn,spanish_iban, spanish_postal_code, spanish_phone, spanish_license_plate spanish_cccand spanish_passport. You can use them in your controllers, form requests, or anywhere Laravel's validator is supported.
Example in a Controller
Example in a Form Request
Customizing Error Messages
Error messages are loaded from the package's language files. After publishing the language files, you can edit them in resources/lang/vendor/laravel-validate-spa/{lang}/validation.php. For example:
If you don't publish the files, the package will use its default messages (if provided) or fall back to Laravel's generic "The :attribute is invalid" message.
Testing the Rules
You can test the validation rules using Laravel's Validator facade in Tinker:
Validation Logic
- NIF/NIE: Validates Spanish NIF (8 digits + letter) and NIE (X/Y/Z + 7 digits + letter) using the official algorithm.
- CIF: Validates Spanish CIF codes (letter + 7 digits + control character) according to the official rules.
- SSN: Validates Spanish Social Security Numbers (12 digits: 2 for province code, 8 sequential digits, and 2 control digits) by checking the province code (01-99) and verifying the control digits using the modulo 97 algorithm.
- IBAN: Validates Spanish IBANs (24 characters: "ES" + 2 control digits + 20-digit bank account number) using the ISO 7064 MOD 97-10 algorithm, ensuring the country code is "ES" and the control digits are correct.
- POSTAL CODE Validates Spanish Postal Code
- PHONE Validates Spanish Phone Number
- VEHICLE LICENSE PLATE Validates Spanish License Plate Car(vehículos Matrículas española)
- CCC Validates Spanish Old Spanish Bank Account, precursor of the IBAN
- PASSPORT Validates Spanish Passport
Contributing
Contributions are welcome! Feel free to submit a pull request or open an issue on the GitHub repository.
License
This package is open-source software licensed under the MIT License.
Laravel Valida Spa was created by [Domingo Albújar] under the MIT license.