Laravel-9 Tutorial – How to Validate Form Input Field using Alpha Rule in Laravel 9

Alpha refers to the field under validation, and it should be utterly alphabetic characters. Alphabetic characters are the traditional characters of the alphabet used to illustrate speech.

In this article, you will learn how to create alpha form validation in Laravel 9 application using alpha form validation rule and Bootstrap CSS library.

Laravel is a great framework that offers many modules and tools to help you build a web application. Likewise, Laravel offers proper form validation rules that help you set various validation conditions in laravel forms.

For the demonstration, we will create a basic responsive form using the latest version of Bootstrap CSS framework in laravel. We will build a laravel app and create a model and controller to manage the laravel alpha from validation.

The ready-made Bootstrap UI components will help us show the proper alpha validation success and error response in laravel.

Laravel 9 Alpha Form Validation Example

  • Build Laravel Application
  • Connect to Database
  • Set Up Model and Migrations
  • Build Form Validation Controller with Alpha
  • Configure View Template
  • Create New Routes
  • Run Laravel Server

Build Laravel Application

To begin with this tutorial, you must have a code editor, terminal app and a composer tool installed and properly configured.

Open the console screen, type the suggested command, and press enter to invoke the command.

composer create-project laravel/laravel --prefer-dist laravel-demo

Next, enter inside the project directory.

cd laravel-demo

Connect to Database

Now, we have to connect the laravel app with the database. You can do it very quickly; just open the .env file and add your database credentials to the file.


For macOS MAMP PHP server; make sure to additionally include UNIX_SOCKET and DB_SOCKET right below the database details in .env file.


Set Up Model and Migrations

In order to store the form value after the form submission, we need to create a model relative to its form value.

php artisan make:model Form -m

Next, a new database/migrations/timestamp_create_forms_table.php file generated you have to go there and define the given code.

use IlluminateDatabaseMigrationsMigration;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateSupportFacadesSchema;
return new class extends Migration
    public function up()
        Schema::create('forms', function (Blueprint $table) {
    public function down()

Head over to app/Models/Form.php file and make sure to define the ‘name’, property in the $fillable array.

namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
class Form extends Model
    use HasFactory;
    public $fillable = [

You are now ready to run the migrations.

php artisan migrate

Build Form Validation Controller with Alpha

We need to generate a new controller, go ahead and execute the following command.

php artisan make:controller FormController

After executing the above command; a new file is generated. Make sure to open the app/Http/Controllers/FormController.php file and add the given code into the file.

namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppModelsForm;
class FormController extends Controller
  public function index() {
    return view('home');
  public function alphaForm(Request $request) {
      $this->validate($request, [
          'name' => 'required|alpha',
      return back()->with('success', 'Form successfully submitted.');

Configure View Template

Enter into the resources/views/ directory; here you have to create a new file.

Ensure that you name it home.blade.php and insert given code into the file.

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="{{ asset('css/style.css') }}">
    <div class="container mt-5">
       <h2 class="mb-4">Laravel Alpha Validation Rule Examle</h2>
            <div class="alert alert-success text-center">
        <form  method="post" action="{{ route('alpha-validate.form') }}" novalidate>
            <div class="form-group mb-2">
                <input type="text" class="form-control @error('name') is-invalid @enderror" name="name" id="name">
                    <span class="invalid-feedback" role="alert">
                        <strong>{{ $message }}</strong>
            <div class="d-grid mt-3">
              <input type="submit" name="send" value="Submit" class="btn btn-danger btn-block">

Create New Routes

Next, we will be building two new routes one for requesting a controller for opening the view template on the browser and another for validating the input.

Make sure to add given code into the routes/web.php file.

use IlluminateSupportFacadesRoute;
use AppHttpControllersFormController;

Route::get('/', [FormController::class, 'index']);
Route::post('/validate-form', [FormController::class, 'alphaForm'])->name('alpha-validate.form');

Run Laravel Server

We have reached to the last step of our guide; now we need to run the laravel app.

Run the command to evoke the server.

php artisan serve

Test your app by opening the app on the browser with given link.

How to Validate Form Input Field using Alpha Rule in Laravel 9


In this step-by-step guide, we have seen the steps that will help us implement alpha validation to the laravel form.

The laravel alpha validation example is used to allow only alpha (alphabetic) characters in the laravel form fields.

Leave a Reply

Your email address will not be published. Required fields are marked *