ItSolutionStuff.com

Special Characters Not Allowed Validation in Laravel

By Hardik Savani β€’ April 16, 2024
Laravel

Now, let's see example of laravel validation no special characters. let’s discuss about laravel validation prevent special characters. i explained simply about special characters not allowed validation in laravel. you can see laravel special characters not allowed validation.

we will use alpha validation rule for not allowed special characters in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 app.

we may sometime requirement to add validation for prevent special characters in our laravel application. so i will show how to validation for not allowed special characters in laravel 7 using laravel alpha. you can easily use with your controller method.

I will give you three way to add validation in laravel. so i will just show you controller code and preview here. so you can also follow form validation with laravel with this code: Laravel Form Validation Example.

You can see bellow preview:

Preview:

Example 1:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class HomeController extends Controller

{

/**

* Show the application dashboard.

*

* @return \Illuminate\Http\Response

*/

public function create()

{

return view('createUser');

}

/**

* Show the application dashboard.

*

* @return \Illuminate\Http\Response

*/

public function store(Request $request)

{

$request->validate([

'name' => 'required|alpha',

'email' => 'required|email|unique:users'

]);

$input = $request->all();

$user = User::create($input);

return back()->with('success', 'User created successfully.');

}

}

Example 2:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class HomeController extends Controller

{

/**

* Show the application dashboard.

*

* @return \Illuminate\Http\Response

*/

public function create()

{

return view('createUser');

}

/**

* Show the application dashboard.

*

* @return \Illuminate\Http\Response

*/

public function store(Request $request)

{

$request->validate([

'name' => 'required|alpha_num',

'email' => 'required|email|unique:users'

]);

$input = $request->all();

$user = User::create($input);

return back()->with('success', 'User created successfully.');

}

}

Example 3:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class HomeController extends Controller

{

/**

* Show the application dashboard.

*

* @return \Illuminate\Http\Response

*/

public function create()

{

return view('createUser');

}

/**

* Show the application dashboard.

*

* @return \Illuminate\Http\Response

*/

public function store(Request $request)

{

$request->validate([

'name' => 'required|regex:/^[a-zA-Z]+$/u',

'email' => 'required|email|unique:users'

]);

$input = $request->all();

$user = User::create($input);

return back()->with('success', 'User created successfully.');

}

}

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

Space Not Allowed Validation in Laravel Example

Read Now β†’
β˜…

Laravel Mobile/Phone Number Validation Example

Read Now β†’
β˜…

Laravel Bail Rule | Stop Validation On First Failure

Read Now β†’
β˜…

Laravel 7 Ajax Form Validation Example

Read Now β†’
β˜…

Laravel 7 Form Validation Tutorial

Read Now β†’
β˜…

Laravel Validation Check If Value is Not Equal to a Another Field

Read Now β†’
β˜…

Laravel Change Password with Current Password Validation Example

Read Now β†’
β˜…

Laravel Validation for Multiple Files in Array Example

Read Now β†’
β˜…

Laravel Ajax Image Upload with Validation Example

Read Now β†’
β˜…

Laravel File Upload with Validation Example

Read Now β†’
β˜…

Laravel Client Side Validation using Parsley.js Example

Read Now β†’