Why you do not like regex? It is perfectly fine and you can do really advanced stuff with it.
Here are 2 resources I always go back to:
Enjoy!
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a use case that is somewhat unique but not particularly weird, and I thought I'd get some input from the community since I can't find a clear answer. I have a FormRequest validating an input field on a form. I'd like to enforce a field to be numeric and have either 10 or 16 digits. Not a range of digits, but specifically those two options.
I found a regex that works, shown here:
public function rules()
{
return [
'MyDigitField' => ['nullable','regex:/^(\d{10}|\d{16})$/'],
];
}
However, instead of regex:/^(\d{10}|\d{16})$/, I'd love to use the format digits:10|16 or digits:10|digits:16, but these do not seem to work from my testing. Does anyone know an elegant way to do this without the regex?
Please or to participate in this conversation.