All Projects → axlon → Laravel Postal Code Validation

axlon / Laravel Postal Code Validation

Licence: mit
Worldwide postal code validation for Laravel and Lumen

Projects that are alternatives of or similar to Laravel Postal Code Validation

Laravel Source Encrypter
Laravel and Lumen Source Code Encrypter
Stars: ✭ 175 (-37.05%)
Mutual labels:  laravel, laravel-package, lumen
Laravel Url Shortener
Powerful URL shortening tools in Laravel
Stars: ✭ 80 (-71.22%)
Mutual labels:  laravel, laravel-package, lumen
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (+14.75%)
Mutual labels:  laravel, laravel-package, lumen
Validator Docs
Validação de CPF, CNPJ, CNH, NIS, Título Eleitoral e Cartão Nacional de Saúde com Laravel.
Stars: ✭ 334 (+20.14%)
Mutual labels:  validation, laravel, laravel-package
Validatorjs
A data validation library in JavaScript for the browser and Node.js, inspired by Laravel's Validator.
Stars: ✭ 1,534 (+451.8%)
Mutual labels:  validation, laravel
Laravel Multistep Forms
Responsable Multistep Form Builder for Laravel
Stars: ✭ 76 (-72.66%)
Mutual labels:  validation, laravel
Laravel Phone
Phone number functionality for Laravel
Stars: ✭ 1,806 (+549.64%)
Mutual labels:  validation, laravel
Validation Composite
Allows uniting of several validation rules into single one for easy re-usage
Stars: ✭ 159 (-42.81%)
Mutual labels:  validation, laravel
Validator
Client-side javascript validator library ports from Laravel 5.2
Stars: ✭ 35 (-87.41%)
Mutual labels:  validation, laravel
Validation
🔒 Laravel farsi/persian validation
Stars: ✭ 142 (-48.92%)
Mutual labels:  validation, laravel
Validation
The power of Respect Validation on Laravel
Stars: ✭ 188 (-32.37%)
Mutual labels:  validation, laravel
Form Object
Form object to use with Vue components for sending data to a Laravel application using axios.
Stars: ✭ 73 (-73.74%)
Mutual labels:  validation, laravel
Laravel Smart
Automatic Migrations, Validation and More
Stars: ✭ 48 (-82.73%)
Mutual labels:  validation, laravel
Laravel Zip Validator
Laravel ZIP file content validator
Stars: ✭ 120 (-56.83%)
Mutual labels:  validation, laravel
Laravel5 Genderize Api Client
Laravel 5 client for the Genderize.io API
Stars: ✭ 47 (-83.09%)
Mutual labels:  validation, laravel
Credit Card
Credit Card Validation
Stars: ✭ 150 (-46.04%)
Mutual labels:  validation, laravel
response
Response HTTP package for Simfony, Laravel, Lumen and PHP 7 with standard REST API
Stars: ✭ 14 (-94.96%)
Mutual labels:  lumen, laravel-package
Laravel-Auto-Hard-Deleter
Laravel and Lumen Auto Hard Deleter
Stars: ✭ 34 (-87.77%)
Mutual labels:  lumen, laravel-package
video-downloader
Video Downloader for Facebook.
Stars: ✭ 63 (-77.34%)
Mutual labels:  lumen, laravel-package
Laravel Nova Excel
🚀 Supercharged Excel exports for Laravel Nova Resources
Stars: ✭ 259 (-6.83%)
Mutual labels:  laravel, laravel-package

Laravel Postal Code Validation

Worldwide postal code validation for Laravel, based on Google's Address Data Service.

Build status Downloads Latest version License

Requirements

This package has the following requirements:

  • PHP 7.2 or higher
  • Laravel (or Lumen) 5.5 or higher
Laravel / Lumen version Package version
5.1 - 5.4 2.x
5.5 and greater 3.x

Installation

You can install this package with Composer, by running the command below:

composer require axlon/laravel-postal-code-validation

If you have package discovery enabled, that's it, continue to the usage section. If you want to register the package manually, you can do this by adding the following line to your config/app.php file:

'providers' => [
   ...
   Axlon\PostalCodeValidation\ValidationServiceProvider::class,
   ...
],

Lumen

If you are using Lumen, register the package by adding the following line to your bootstrap/app.php file:

$app->register(Axlon\PostalCodeValidation\ValidationServiceProvider::class);

Usage

Postal code validation perfectly integrates into your Laravel application, you can use it just like you would any framework validation rule.

Available rules

This package adds the following validation rules:

postal_code:foo,bar,...

The field under validation must be a valid postal code in at least one of the given countries. Arguments must be countries in ISO 3166-1 alpha-2 format.

'postal_code' => 'postal_code:NL,DE,FR,BE'

postal_code_with:foo,bar,...

The field under validation must be a postal code in at least one of the countries in the given fields only if at least one of the specified fields is present.

'billing.country' => 'required|string|max:2',
...
'shipping.country' => 'nullable|string|max:2',
'shipping.postal_code' => 'postal_code_with:billing.country,shipping.country'

Fluent API

If you prefer using a fluent object style over string based rules, that's also available:

'postal_code' => [
    PostalCode::for('NL')->or('BE'),
],

The same goes for the postal_code_with rule:

'billing.country' => 'required|string|max:2',
...
'shipping.country' => 'nullable|string|max:2',
'shipping.postal_code' => [
    PostalCode::with('billing.country')->or('shipping.country')
],

Adding an error message

To add a meaningful error message, add the following lines to resources/lang/{your language}/validation.php:

'postal_code' => 'Your message here',
'postal_code_with' => 'Your message here',

The following placeholders will be automatically filled for you:

Placeholder Description
:attribute The name of the field that was under validation
:countries The countries that were validated against (e.g. NL, BE)*
:examples Examples of allowed postal codes (e.g. 1234 AB, 4000)*

*The :countries and :examples placeholders may be empty if no valid countries are passed.

Manually validating

If you want to validate postal codes manually outside of Laravel's validation system, you can call the validator directly, like so:

PostalCodes::passes($country, $postalCode); // returns a boolean

Overriding rules

Depending on your use case you may want to override the patterns used to validate postal codes for a country. You can do this by adding the code below in a central place in your application (e.g. a service provider):

PostalCodes::override('country', '/your pattern/');

// You can also pass overrides as an array

PostalCodes::override([
    'country 1' => '/pattern 1/',
    'country 2' => '/pattern 2/',
]);

Important: If you believe there is a bug in one of the patterns that this package ships with, please create an issue in the issue tracker.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

This open-source software is licenced under the MIT license. This software contains code generated from Google's Address Data Service, more information on this service can be found here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].