isEmail

Test if a value is an email address.

Usage

var isEmail = require( '@stdlib/assert/is-email-address' );

isEmail( value )

Tests if a value is an email address.

var bool = isEmail( 'beep@boop.com' );
// returns true

Notes

  • Validation is not rigorous, nor should it be. 9 RFCs relate to email addresses, and accounting for all of them is a fool's errand. This module performs the simplest validation; i.e., requiring at least one @ symbol.
  • For rigorous validation, send a confirmation email. If the email bounces, consider the email invalid.

Examples

var isEmail = require( '@stdlib/assert/is-email-address' );

var bool;

bool = isEmail( 'beep@boop.com' );
// returns true

bool = isEmail( 'beep' );
// returns false

bool = isEmail( 'beep.com' );
// returns false

bool = isEmail( null );
// returns false

CLI

Usage

Usage: is-email-address [options] [<string>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --split sep           Delimiter for stdin data. Default: '/\\r?\\n/'.

Notes

  • If the split separator is a regular expression, ensure that the split option is either properly escaped or enclosed in quotes.

    # Not escaped...
    $ echo -n $'foo@bar.com\nboop' | is-email --split /\r?\n/
    
    # Escaped...
    $ echo -n $'foo@bar.com\nboop' | is-email --split /\\r?\\n/
    
  • The implementation ignores trailing delimiters.

Examples

$ is-email-address beep@boop.com
true

To use as a standard stream,

$ echo -n 'beep@boop.com' | is-email
true

By default, when used as a standard stream, the implementation assumes newline-delimited data. To specify an alternative delimiter, set the split option.

$ echo -n 'foo@bar.com\tbeep' | is-email --split '\t'
true
false
Did you find this page helpful?