I have validation rule:
$rules = ['username' => 'required|string|alpha_dash']
I need prevent dash in validation, allow only underscores, letters and numbers. How I can do it? Now alpha_dash allow dashes..
I would suggests to use regex
validation to get more power to customize in future if you wish. SEE https://laravel.com/docs/5.8/validation#rule-regex
'regex:/^[A-Za-z0-9_]+$/'
or more specifically
$rules = ['username' => 'required|string|regex:/^[A-Za-z0-9_]+$/']
Because as per documentation alpha_dash
supports-
The field under validation may have alpha-numeric characters, as well as dashes and underscores.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With