Skip to content
NewRedesigned blogFeedback
Jigar Karangiya

How to validate email address in Magento 2 programmatically?

In Magento 2, You can use the native Magento\Framework\Validator\EmailAddress class to validate email address programatically.

How to validate email address in Magento 2 programmatically?
Written by
JKJigar Karangiya
Published
Reading time
1 min read

Jigar Karangiya · · 1 min read

Validating emails in Magento 2 is very crucial because it helps to make sure you don’t get any fake email submissions and that the information provided by users is proper.

You can validate email addresses programmatically inside the PHP-based files of your Magento 2 codebase.

You can use native
Magento\Framework\Validator\EmailAddress emailValidator class to validate email address.

Let’s understand it with a quick and easy example.

php
<?php
/**
 *
 * Tutorial by Jigar Karangiya Blogs, hello@jigarkarangiya.com
 * Visit jigarkarangiya.com for more magento 2 blogs.
 */
use Magento\Framework\Validator\EmailAddress as EmailValidator;
use Magento\Framework\App\ObjectManager;
 
/**
 * Validate email address format
 *
 */
class YourClass 
{
 
    /**
     * @var EmailValidator
     */
    private $emailValidator;
 
    /**
     * Initialize dependencies.
     *
     * @param EmailValidator $emailValidator
     */
    public function __construct(
        EmailValidator $emailValidator = null
    ) {
        $this->emailValidator = $emailValidator ?: ObjectManager::getInstance()->get(EmailValidator::class);
    }
    
 
    /**
     * Validates the format of the email address
     *
     * @param string $email
     * @throws Exception
     * @return boolean
     */
    public function isValidEmail($email)
    {
        try {
            if (!$this->emailValidator->isValid($email)) {
                return false;
            } else {
                return true;
            }
        } catch (Exception $e) {
            //Handle exception here
        }
    }
}

You can then use it using by calling function $this- >isValidEmail(‘hello@jigarkarangiya.com (opens in new tab)’);

It will return true or false based on the email address provided.

I hope this article helped you to find what you were looking for.

Bookmark it for your future reference. Do comment below if you have any other questions on that.

Do share this blog with your team.

You will also like this :

how to get shared catalog data by ID in Magento 2?

Get Company using Customer ID programmatically Magento 2 B2B

Get Company Admin using company ID programmatically Magento 2 B2B

Keep reading
All posts

01 · 10 min · Shares Adobe Commerce Core

Adobe Commerce Agentic Capabilities, Q4 2026

Five agentic releases for Adobe Commerce: LLM product discovery, Brand Visibility, the Shopper MCP server, Brand Concierge, and Experience Workspace. What each one does, which editions get it, and when.

10 min

03 · 3 min · Shares Adobe Commerce Core

Conditions for Collections in Magento 2

Collections in Magento 2 (Now Adobe Commerce), are among the most powerful tools for retrieving and manipulating data directly from the database.

3 min

Newsletter

New Magento tutorials, straight to your inbox

Code examples, performance tips, and fixes for common Magento issues. No spam.

Subscribe