square / laravel-hyrule

Object-oriented, composable, fluent API for writing validations in Laravel
Apache License 2.0
340 stars 10 forks source link

Regex with laravel-hyrule #1

Closed RenatoKW closed 2 years ago

RenatoKW commented 2 years ago

Is there a way to use regular expressions with this API? Haven't see any mentions in the documentation for this. Ty

bezhermoso commented 2 years ago

Any and all built-in rules in Laravel is possible :) Just use the rule name as if it's a method in the builder, and it will be appended as a rule. For example, you can use regex like so:

$builder = Hyrule::create()
    ->string('slug')
       ->regex('/^[a-z0-9\-]$/')
       ->end()
    // etc.
RenatoKW commented 2 years ago

Very Nice!! Thanks for the quick reply!!