Laravel custom validation rules.
This package requires you to use Laravel version 8. Install this package through Composer.
$ composer require risan/lara-rules
use Risan\LaraRules\USPhoneWithDash;
$request->validate([
'phone' => ['required', 'string', new USPhoneWithDash], // Valid: 123-456-7890
'state' => ['required', 'string', new USStateCode], // Valid: CA, TX
'zip_code' => ['required', 'string', new USZipCode], // Valid: 90120 or 20521-9000
]);
USPhoneWithDash
: 10 digits of US phone number with dash.USStateCode
: 2 characters of US state code.USZipCode
: 5 or 9 digits of US zip code.