Reputation: 4806
I have text box which will accept number or alphabets based on my requirements
Ex: 1234 - correct, abcd - correct, 123abc - wrong
So i need 'my_texbox' => 'alpha|numeric'
as or condition but it was by default and condition.
Is there any way to achieve this other than custom validation?
Upvotes: 1
Views: 1445
Reputation: 10631
You can try this
use Illuminate\Support\Facades\Validator;
and
$arr=['name'=>'123'];
$rule=['name'=>array('regex:/(?:^([^a-b]*)$|^([^0-9]*)$)/')];
$accept=Validator::make($arr,$rule);
dd($accept->fails());
Output
1234 - correct, abcd - correct, 123abc - wrong
Upvotes: 1