Laravel validation no space allowed for username

You can extend the validator with your own custom rules:

Validator::extend('without_spaces', function($attr, $value){
    return preg_match('/^\S*$/u', $value);
});

Then just use as any other rule:

required|without_spaces|unique:user_detail,username

Checkout the docs on custom validation rules:

https://laravel.com/docs/5.2/validation#custom-validation-rules


Why don't you use alpha_dash rule?

required|alpha_dash|unique:user_detail,username

From the documentation:

The field under validation may have alpha-numeric characters, as well as dashes and underscores.

And it doesn't allow spaces.