Published on

How to check or extract Email Addresses in Javascript


At one point or another, we might have come across the case in which we need to do a proper email validation or extract email address from a string.

For our case, we'll be using a tiny npm package email-regex

Install the Dependencies

npm install email-regex

This package is just a helper function for the email regex - nothing more, nothing less


import emailRegex from 'email-regex';

// Check if the string contains email address
emailRegex().test('hello'); // true

// Check if has only email string
emailRegex({exact: true}).test('hello'); // false

// Extract email from a string
// ['', '']

Happy extracting email-addresses!