Level 73
Use regex in your validation rule.
I think this one should do the trick
'user' => 'regex:/^([a-z])+?(-|_)([a-z])+$/i'
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want this rules for my username field:
Not valid :
__name-----
name____-----
user_____name
Valid :
user-name
user_name
I found laravel alpha_dash helpful for this, But the problem is, it allows multiple dash and underscore also in start and end, I know we can handle this with regex but is there any quick and laravel way ?
Please or to participate in this conversation.