email-address-util
v1.0.0
Published
Utilities for working with email addresses
Downloads
1
Maintainers
Readme
email-address-util
Utilities for working with email addresses
Usage
# Install the package
npm install email-address-util
# Require it in your JS file
const EmailUtil = require("email-address-util");
Validate
Validate that the given string is a valid email address. This method uses the regular expression from W3, then validates the domain against IANA's list of valid TLDs.
EmailUtil.validate("[email protected]") # => true
EmailUtil.validate("in([email protected]") # => false
Extract
Extract the first email address found in the given string. Uses the same regular
expression as validate
.
const strWithEmail = "My email address is [email protected]";
const strWithoutEmail = "My email address is above";
EmailUtil.extract(strWithEmail) # => "[email protected]"
EmailUtil.extract(strWithoutEmai) # => false
Tests
Run tests with npm test
.