Laravel Postal Code Validation
· 916
Wajdi Alkayal Wajdi Alkayal


Postal code validation for multiple countries can always be a pain, but thanks to the Laravel Postal Code Validation package by Choraimy Kroonstuiver, validating postal codes is a breeze:

1$this->validate($request, [
2 'postal_code' => 'postal_code:NL,BE',
3]);

Here’s a fluent version of the rule:

1$this->validate($request, [
2 'postal_code' => [
3 PostalCode::forCountry('NL')->andCountry('BE'),
4 ],
5]);

This package supports worldwide postal code validation, enabling your forms to support multiple postal codes or single out a specific postal code based on the user’s current locale for example.

As an interesting aside, I recently found this helpful list of regular expressions from the Common Locale Data Repository (CLDR) if you’re interested in regular expression postal code validation rules for every territory in the world. Here’s a Gist of the CLDR regex rules as a PHP array available on GitHub.

To start using this package, check out the source code and readme at axlon/laravel-postal-code-validation on GitHub.


Related Posts
Graphic design
09 June
The Power of Email Marketing
03 June
Photography
01 June

WMK Tech Copyright © 2024. All rights reserved