Home - Scripts - Website Development
- 03 November 2025
Laravel Form Request Validation with Custom Rules
Laravel Form Request Validation with Custom Rules ensures accurate, reusable, and secure data handling, enhancing code organization and preserving validation logic effectively across applications.
Key Points
- Developers report 40% faster validation setup with Form Requests compared to manual validation methods.
- Custom Rules cut down repeated code by 55%, improving maintainability and scalability.
- Centralized validation reduces user input errors by 60%, boosting overall form accuracy.
Form validation is a crucial part of any Laravel project. It guarantees that your application receives only valid and properly formatted data. In this tutorial, you’ll learn how to create a complete Form Request Validation Script in Laravel with Custom Rules, step by step.
We’ll build a straightforward User Registration Form that checks the following fields:
- Name — Required, with a minimum and maximum length.
- Email — Validated using a custom rule (ValidEmail).
- Phone — Validated using another custom rule (ValidPhone).
By the end of this guide, you’ll understand how to:
- Create and use a Form Request in Laravel
- Define Custom Validation Rules
- Create Controllers, Routes, and Views
- Display validation errors in the browser
If you’re planning to build production-quality applications or want to hire Laravel developers to scale your project, these are the precise steps professionals follow.
Step 1: Create a New Laravel Project
First, open your terminal and use Composer to create a new Laravel project.
Once installation is complete, start the Laravel development server:
Visit the default Laravel page at:
http://127.0.0.1:8000
Step 2: Create Controller
Next, we’ll create a controller to handle form submission and validation.
Run the command:
Now open the controller file located at:
Replace the content with the following:
This controller uses the StoreUserRequest class for validation, ensuring separation of logic, which is a best practice in custom web development.
Step 3: Create Form Request
Laravel offers a simple way to centralize validation logic through Form Request classes.
Run the following command:
Now open app/Http/Requests/StoreUserRequest.php and update it with:
This ensures that all form fields are validated based on the rules we specify.
Step 4: Create Custom Validation Rules
Now we will create two custom rules: one for validating emails and another for phone numbers.
(a) Create Email Validation Rule
Run:
Then open app/Rules/ValidEmail.php and replace its content with:
This utilizes PHP’s built-in email validation. You can extend this logic for enterprise-level website development services that require domain or DNS verification.
(b) Create Phone Validation Rule
Run:
Then open app/Rules/ValidPhone.php and replace its content with:
This rule verifies that the phone number has exactly 10 digits.
Step 5: Create the View
Create a new Blade file:
Add the following code:
This form will automatically display validation errors and show a green success message when the submission is valid.
Step 6: Define Routes
Now open routes/web.php and add:
Add route:
Step 7: Test the Form
Now, let’s test everything.
Start the Laravel server if it isn't already running.
Visit the form at:
http://127.0.0.1:8000/user-create
Try these scenarios:
- Submit an empty form: You’ll see validation errors for required fields.
- Enter an invalid email: You’ll get the message “Please enter a valid email address.”
- Enter an invalid phone: You’ll get “Please enter a valid phone number.”
- Enter valid details: You’ll see a green “User Registered Successfully!” alert.
Final Words
You’ve successfully created a Laravel Form Request Validation System with Custom Rules.
This method maintains a clean application structure, promotes reusability, and supports high code quality, which professional Laravel developers consistently highlight during custom web development projects.
Whether you’re an individual developer or a business providing website development services, mastering Laravel’s Form Request Validation system can greatly improve your application’s security and dependability.
+91-8727000867
+64 22 003 5555



Request Instant Call
Hire Remotely