Laravel Validation Rules is a GitHub organization containing a collection of useful validation rules that you can pull into any project quickly and not have to write them yourself. At the time of writing here’s the list of validation rule packages:
- Colour (currently supports hex)
- Country Codes
- Credit Card
- IP
- Phone
- Subdomain
- Timezone
- US States and CA Provinces
Here’s an example from the documentation using the US states validation package:
1use LVR\State\Abbr; 2use LVR\State\Full; 3 4# Abbreviation vs Full 5$request->validate(['test' => 'UT'], ['test' => new Abbr]); // Pass! 6$request->validate(['test' => 'BC'], ['test' => new Abbr); // Pass! 7$request->validate(['test' => 'Utah'], ['test' => new Full]); // Pass! 8$request->validate(['test' => 'Alberta'], ['test' => new Full]); // Pass! 9 10# Abbreviation - USA vs Canada11$request->validate(['test' => 'UT'], ['test' => new Abbr]); // Pass!12$request->validate(['test' => 'UT'], ['test' => new Abbr('US')]); // Pass!13$request->validate(['test' => 'BC'], ['test' => new Abbr('CA')); // Pass!14 15# Full - USA vs Canada16$request->validate(['test' => 'Utah'], ['test' => new Full('US')]); // Pass!17$request->validate(['test' => 'Alberta'], ['test' => new Full('CA')]); // Pass!
To learn more about this project, check out the Laravel Validation Rules documentation. You can view the source code of the various validators by browsing repositories in the GitHub organization.
0 comments:
Post a Comment
Thanks