Socket
Book a DemoInstallSign in
Socket

@toolz/looks-like-email

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@toolz/looks-like-email

A utility function that determines whether a given string looks like a valid email address

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

looks-like-email

looks-like-email is a utility function that determines whether a string looks like a valid email address. Obviously, this function cannot tell whether a string represents a working email address. But this utility performs a series of checks to ensure that the input at least appears to be a valid email address.

Usage

After installation, import the package:

import { looksLikeEmail } from '@toolz/looks-like-email';

looksLikeEmail()

Given any string, looksLikeEmail() performs the following validates that:

  • The string contains exact one @ symbol.
  • The @ symbol does not appear the beginning or end of the string. (The portion before the @ symbol is the "local part". The portion after it is the "domain part").
  • The local part consists of alphanumerics and/or the following characters: ! # $ % & ‘ * + - / = ? ^ _ ` . { | } ~
  • There are no consecutive periods in the local part.
  • The domain part is no longer than 255 characters.
  • There is some kind of top-level domain in the domain part. (Given the every fluctuating directory of TLDs, this utility does not try to validate that the supplied TLD is a real TLD.)
  • The domain part is divided into domain labels by periods - and there are at least two domain labels.
  • No domain label exceeds 63 characters in length.
  • Each domain label consists of alphanumerics and/or a hyphen.
  • Domain labels do not start or end with a hyphen.

This utility uses @toolz/string-contains to look for alphanumerics across the UTF-8 spectrum. This means that letters are accepted when they are outside the ASCII range.

const API = {
   arguments: {
      string: {
         required,
         format: string,
      },
      showWarnings: {
         optional,
         format: Boolean,
         defaultValue: false,
      },
   },
   returns: Boolean,
}

Examples:

looksLikeEmail('adam@bytebodger@foo.com'); // FALSE
looksLikeEmail('@adambytebodger.com'); // FALSE
looksLikeEmail('abcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzy@bytebodger.com'); // FALSE
looksLikeEmail('adambytebodger.com@'); // FALSE
looksLikeEmail('ad[am@bytebodger.com'); // FALSE
looksLikeEmail('ad..am@bytebodger.com'); // FALSE
looksLikeEmail('abc@defghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzydefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzyabcdefghijklmnopqrstuvwxzybytebodger.com'); // FALSE
looksLikeEmail('adam@bytebodgercom'); // FALSE
looksLikeEmail('adam@bytebodgerbytebodgercombytebodgercombytebodgercombytebodgercombytebodgercombytebodgercombytebodgercom.com'); // FALSE
looksLikeEmail('adam@byte*bodger.com'); // FALSE
looksLikeEmail('adam@byte.-bodger.com'); // FALSE
looksLikeEmail('adam@byte-.bodger.com'); // FALSE
looksLikeEmail('adam@byte-.bodger.com', true); // FALSE (with console warning about the error)
looksLikeEmail('adam@byte.bodger.com'); // TRUE
looksLikeEmail('adam_davis1@byte.bodger.com'); TRUE

Keywords

email

FAQs

Package last updated on 19 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts