validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

Bug: `isEmail` docs/source suggest `allow_underscores` is defaulted to `false` however `[email protected]` is valid by default

Open titanism opened this issue 1 year ago • 4 comments

As described in title.

titanism avatar Nov 27 '24 16:11 titanism

I think this is expected behaviour. According to RFC 5322, an underscore can appear in the local-part of the email address and is a valid character (when used before @). The underscore is not allowed in the domain name; however, there are some cases where it could appear in a subdomain. This is what allow_underscores flag is for.

If you want to exclude underscore from local-part of the email, use blacklisted_chars option:

validator.isEmail('[email protected]', { blacklisted_chars: '_' }) // false

jamro avatar Dec 08 '24 10:12 jamro

@jamro see https://github.com/validatorjs/validator.js/issues/2508

titanism avatar Dec 12 '24 22:12 titanism

Given the expected behavior, I think we can go ahead and close this issue.

jinang17 avatar Aug 14 '25 20:08 jinang17

The docs and option indicate otherwise..

titanism avatar Aug 14 '25 22:08 titanism