diff --git a/content/1.getting-started/5.strategies.md b/content/1.getting-started/5.strategies.md index 2d240f4..2160c79 100644 --- a/content/1.getting-started/5.strategies.md +++ b/content/1.getting-started/5.strategies.md @@ -43,3 +43,17 @@ $faker = new Faker(); $faker->regex('/^01$/')->postalCode(); // Postal code that begins with '01' $faker->regex('/.com$/')->email(); // Email that ends with '.com' ``` + +## Valid + +The valid strategy allows you to filter generated values using a custom validation callable. The callable must accept one parameter (the generated value) and return a boolean indicating whether the value is valid or not. + +```php +use Xefi\Faker\Faker; + +$faker = new Faker(); + +$faker->valid(function ($number) {return $number % 2 === 0; })->numberBetween(1, 100); // Even numbers +$faker->valid(fn ($number) => $number % 2 !== 0)->numberBetween(1, 100); // Odd numbers +$faker->valid(fn ($email) => str_ends_with($email, '.org'))->email(); // Emails that ends by '.org' +```