Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spaces are accepted before @ sign #21

Open
dcarniel opened this issue Mar 8, 2021 · 4 comments
Open

Spaces are accepted before @ sign #21

dcarniel opened this issue Mar 8, 2021 · 4 comments

Comments

@dcarniel
Copy link

dcarniel commented Mar 8, 2021

Hi,

I noticed that spaces are accepted before the @ sign of the email address, values such as "jo [email protected]", "john. [email protected]" or "john.doe @example.com" are not flagged as invalid, here is an example of result obtained:

jo [email protected]:
{
  "valid": true,
  "validators": {
    "regex": {
      "valid": true
    },
    "typo": {
      "valid": true
    },
    "disposable": {
      "valid": true
    },
    "mx": {
      "valid": true
    },
    "smtp": {
      "valid": true
    }
  }
}

This test is done with the following code:

async function checkEmail( email: string ) {
  const valid = await validate({
    email: email,
    sender: email,
    validateRegex: true,
    validateMx: true,
    validateTypo: true,
    validateDisposable: true,
    validateSMTP: false,
  });
  logger.error( `${email}:\n${JSON.stringify( valid, null, 2)}` );
}

I would expect it to fail at the regexp stage. For sure an address with a space in that part is refused by email servers.

Let me known if you need any more details.
Denis

@dcarniel
Copy link
Author

dcarniel commented Mar 8, 2021

I also have another corner case which I would expect be caught: [email protected]. is actually reported as correct if the typo check is disabled.
I would expect this to be caught by the regexp validation. It is very annoying as many modern browsers add a period when pressing space twice. I can easily trim the input but that won't remove the trailing dot.

@mfbx9da4
Copy link
Owner

mfbx9da4 commented Nov 24, 2021

Checking for spaces is beyond this

The philosophy of this lib is to be really light on validating the format of an email as that notoriously produces a lot of false alarms. Spaces are actually valid I believe in some cases, so I won't be adding that. If you want just regex I recommend validator.

The latter complaint is fair though. This lib should definitely validate that the email should not end with ..

const [domain] = split.slice(-1)
if (domain.indexOf('.') === -1) {
return 'Must contain a "." after the "@".'
}

Should add

   if (domain.endsWith('.')) {
      return 'Must not end with "."'
    }

@dcarniel-evorra
Copy link

I agree that you don't want to generate too many false alarms. Though I'd expect that spaces are only before or right after characters such as <> or "" that mark a readable name associated with the actual email.
There certainly should not be any spaces in the actual email part, though I must admit I'm not sure to put that together in a reliable RegExp ;).

zingerj added a commit to zingerj/deep-email-validator that referenced this issue Apr 27, 2022
@conradkirschner
Copy link

conradkirschner commented Feb 4, 2023

I also have another corner case which I would expect be caught: [email protected]. is actually reported as correct if the typo check is disabled. I would expect this to be caught by the regexp validation. It is very annoying as many modern browsers add a period when pressing space twice. I can easily trim the input but that won't remove the trailing dot.

https://stackoverflow.com/a/49153802

Isn't is a valid domain? So email should also be valid in this case.

mfbx9da4 pushed a commit that referenced this issue Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants