Joi: Invalid regex for Joi.string().email()

Created on 26 Nov 2017  路  6Comments  路  Source: sideway/joi

Context

  • node version: v8.6.0
  • joi version: 13.0.2
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce ?

I tried using "email@nodomain" as an email, which should be rejected due to invalid email format. But, is accepting the input.

Describe your issue here, include schemas and inputs you are validating if needed.

const schema = Joi.object().keys({
    email: Joi.string().email().required(),
});

Which result you had ?

On trying "email@nodomain" accepts the string input as an email. Whereas it must reject it since the domain is invalid.

What did you expect ?

The correct regex for email must be

/^([a-zA-Z0-9_-.]+)@([a-zA-Z0-9_-.]+).([a-zA-Z]{2,5})$ /

This would allow only "[email protected]" or such type of strings to pass as email.

non issue

Most helpful comment

Have you at least read the response I gave ?

All 6 comments

Nope, it's a valid email. Read the options and search issues about minDomainAtoms.

The above issue is still not fixed on [email protected], could this be fixed with correct regex in any of the versions coming up

Have you at least read the response I gave ?

I can understand in a way regarding minDomainAtoms but would it not be more sensible to cater to the majority of use cases where we'd expect this by default to be set to 2?

But isemail isn't about catering to specific use-cases. It is geared toward following the RFCs that dictate what is and isn't a valid email. So the defaults are to follow the RFCs as closely as possible. Options like minDomainAtoms are added on top of the RFCs to allow people to limit emails to be more restrictive than RFC.

Hmm I agree, think I'm coming from the angle of it not being super obvious at a glance and a documentation tweak should hopefully prevent some confusion.

I've submitted a PR for an update to the README.md

Was this page helpful?
0 / 5 - 0 ratings

Related issues

REBELinBLUE picture REBELinBLUE  路  3Comments

longweiquan picture longweiquan  路  3Comments

Taxi4you picture Taxi4you  路  3Comments

kevbook picture kevbook  路  4Comments

alekbarszczewski picture alekbarszczewski  路  3Comments