GithubHelp home page GithubHelp logo

email-regex's Introduction

email-regex

Regular expression for matching email addresses

Use it for finding email addresses or checking if something is email like.

You shouldn't use this for validating emails. Only for hinting to the user.

Install

npm install email-regex

Usage

import emailRegex from 'email-regex';

// Contains an email address
emailRegex().test('unicorn [email protected]');
//=> true

// Is an email address
emailRegex({exact: true}).test('[email protected]');
//=> true

'unicorn [email protected] cake [email protected] rainbow'.match(emailRegex());
//=> ['[email protected]', '[email protected]']

API

emailRegex(options?)

Returns a regex for matching email addresses.

options

Type: object

exact

Type: boolean
Default: false (Matches any email address in a string)

Only match an exact string.

Useful with RegExp#test to check if a string is an email address.

Important

If you run the regex against untrusted user input in a server context, you should give it a timeout. It's also a good idea to limit the input to a reasonable length.

I do not consider ReDoS a valid vulnerability for this package.

email-regex's People

Contributors

evagy avatar fibo avatar jamiekyle-eb avatar kevva avatar moetezch avatar richienb avatar samverschueren avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

email-regex's Issues

Next.js import error

Getting this when trying to use email-regex:

Error: Must use import to load ES Module: /Users/alex/repos/reflect/node_modules/email-regex/index.js
require() of ES modules is not supported.
require() of /Users/alex/repos/reflect/node_modules/email-regex/index.js from /Users/alex/repos/reflect/node_modules/@team-reflect/reflect-editor/dist/extensions/contact-extension/options.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/alex/repos/reflect/node_modules/email-regex/package.json.```

ESModules are giving too much trouble

Just wanted to note here that I (and probably a lot of other people who installed this package) spent about 2 days trying to make this package work with our front-end and then back-end. A lot of changes had to be done to TypeScript, Node (package.json), Jest (had to mock it), Docker. A lot of wasted hours on googling and fixing different issues and eventually decided to stop it and switch to older version of this package (v4.0.0).

It would be great if it would support both ESM and CommonJS, using the new "exports" property that can be used to separate entry-points for CommonJS and ESM:

// package.json
{
    "name": "my-package",
    "type": "module",
    "exports": {
        ".": {
            // Entry-point for `import "my-package"` in ESM
            "import": "./esm/index.js",
            // Entry-point for `require("my-package") in CJS
            "require": "./commonjs/index.cjs",
        },
    },
    // CJS fall-back for older versions of Node.js
    "main": "./commonjs/index.cjs",
}

`[email protected]` should a invalid regexp

[email protected] should a invalid email.
I think maybe this repo want check it, as below code in index.js

const re = '[^\\.\\s@:][^\\s@:]*(?!\\.)@[^\\.\\s@]+(?:\\.[^\\.\\s@]+)*';

the regexp snippet [^\\s@:]*(?!\\.)@ is also match .@
Because the ?! only match a position not a indeed character. It like (?=@)@ equal to @. and (?![^@])@ equal to @. the character before @ always match the position (?=@) and (?![^@]), the regexp snippets in the repo code (?!\\.) is a subset of (?![^@]), it is reason

  • If, emailRegex({exact: true}).test('[email protected]') return true is working as Intended. The regexp snippet (?!\\.) is useless, it should be remove. Just like below
const re = '[^\\.\\s@:][^\\s@:]*@[^\\.\\s@]+(?:\\.[^\\.\\s@]+)*';
  • If emailRegex({exact: true}).test('[email protected]') should return false, the regexp should change like below:
const re = '[^\\.\\s@:](?:[^\\s@:]*[^\\s@:\\.])?@[^\\.\\s@]+(?:\\.[^\\.\\s@]+)*';

If it is the sencond position, I will pull request to fix it and add test.

Noticing some odd matches

I was testing a few blobs of text with this regex rule but found some odd matches such as:

f="nr@context",c=e("gos")

This should return zero results, but, it returns : f="nr@context",c=e("go as a match.

Have you seen some of the regex suggestions here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.