Hapi: Joi.string().email() without options object returns Error: Built-in TLD list disabled

Created on 21 Feb 2020  路  2Comments  路  Source: hapijs/hapi

Context

  • node version: v13.3.0
  • module version: 17.1.0

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


I have this validation scheme

const loginSchema = Joi.object({
  email: Joi.string()
    .email()
    .required(),
  password: Joi.string().required(),
})

when validating I get Error: Built-in TLD list disabled. From the documentation https://hapi.dev/family/joi/api/?v=17.1.0#stringemailoptions I get that options are, well, optional. I tried passing { tlds: {allow: true} } but I get the same error. After researching I found out that you removed tlds validation support in order to reduce your bundle, so maybe documentation needs update too.

support

Most helpful comment

As per the documentation

tlds - options for TLD (top level domain) validation. By default, the TLD must be a valid name listed on the IANA registry. To disable validation, set tlds to false.

Means you must be specific and give a valid tlds option with a list of TLDs you want to validate, to disable this error message just do:
email: Joi.string().email({ tlds: {allow: false} })

this will make Joi accepts any type of TLDs and continue your validation without any errors

All 2 comments

As per the documentation

tlds - options for TLD (top level domain) validation. By default, the TLD must be a valid name listed on the IANA registry. To disable validation, set tlds to false.

Means you must be specific and give a valid tlds option with a list of TLDs you want to validate, to disable this error message just do:
email: Joi.string().email({ tlds: {allow: false} })

this will make Joi accepts any type of TLDs and continue your validation without any errors

You seem to be using the browser build of joi instead of the node version...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leore picture leore  路  4Comments

mateeyow picture mateeyow  路  5Comments

arb picture arb  路  4Comments

andkazakov picture andkazakov  路  5Comments

DrMabuse23 picture DrMabuse23  路  5Comments