I'm using Ravel to create an input form.
I would like to use regular expressions in the validation rules and specify 4 digits or a blank to check the input, but when I specify regex, the blank gets stuck in the validation.
For example,
$rules=[
'value1' = > ['regex:/^\d{4}$/',
'value2' = > ['regex:/^(\d{4})?$/']
'value3' = > ['regex:/^(\d{4}|\s*)$/',
'value4' = > ['regex:/^(\d{4}|\n*)$/',
'value5' = > ['regex:/^(\d{4}|*)$/' ]
];
I have tried this method, but if I submit it blank, it will get stuck in validation.
I've tried other possible methods, but I can't.
When I set regex to begin with, I think the blanks are also disabled.
'value'=>['regex://\s*/']
By the way, take out \d and use a method like ↑.
'value'=>['regex:/.*/']
I also tried ↑, but both of them said it was a full-width space, but it didn't work if it was a half-width space or a blank space.
How should I set it up?
php laravel
I was able to set it up using nullable
'value'=>['nullable', 'regex:/^\d{4}$/',
Configure one validation instead of adding it to the regular expression.
When using |(pipe) within regex, |(pipe) cannot be used to separate variations, so it is not necessary, so
'value'=>'nullable|regex:/^\d{4}$/',
It's done now.
Thank you.
© 2024 OneMinuteCode. All rights reserved.