The alpha_num filter just checks if the username contains only letters and numbers but not if both are present.
Depending on your need, there are two regex that can validate the username
If you want (at least) one letter and one number and whatever else
if (preg_match('/[A-Za-z]/', $myString) && preg_match('/[0-9]/', $myString))
{
echo 'Contains at least one letter and one number';
}
1a]-/*+
and aaaaaaaa1
will pass this test
1-_%
and a
will not pass the test
If you want (at least) one letter and one number but only letters and numbers
if (preg_match('/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/', $myString))
{
echo 'Contains at least one letter and one number and only alphanum';
}
more info about this regex : https://regex101.com/r/GrLGbT/1
1111111a
and aaaaaaaa1
will pass this test
1a-
and a
will not pass the test
Once you have your regex, you will need to create a custom validator. Have a look here for the doc : https://laravel.com/docs/5.3/validation#custom-validation-rules