Laravel Email .(dot) Validation Example
Teams applying “Laravel Email .(dot) Validation Example” in a production project can use this workflow reference to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.
Before copying the example into a live application, confirm version-specific behaviour with the official Laravel website and test it against the project’s actual database and runtime.
Oct 23, 2020
Now let's see example of how to validate an eamil address in laravel and php. We will show email validation in laravel. we will learn how to validate an email with regex in laravel. if you want to check .(dot) from the email address exist or not. The problem is when I remove . (dot) from the email address, it accepts it as a invalid email address.
This article will give you how to validate .(dot) from email address in laravel and php. I will give three solution for .(dot) validation of email address in php laravel. one solution in laravel and two solution in php. So let's see the bellow solution.
Solution : In Laravel
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function store(Request $request)
{
$request->validate([
'email' => 'regex:/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix'
]);
}
Solution 1 : In PHP
The function preg_match() checks the input matching with patterns using regular expressions.
<?php
function validEmail($str) {
return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if(!validEmail("abc@abccom")){
echo "Invalid email address.";
}
else{
echo "Valid email address.";
}
?>
Output
Invalid email address.
In the above example PHP preg_match() function has been used to search string for a pattern and PHP ternary operator has been used to return the true or false value based on the preg_match return.
Solution 2 : In PHP
In this solution we will use filter_var() method for email validation in php.
<?php
function checkemail($str) {
return (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if(!checkemail("[email protected]")){
echo "Invalid email address.";
}
else{
echo "Valid email address.";
}
?>
Output
Valid email address.
It will help you....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial