JOI email validation

Konrad Albrecht picture Konrad Albrecht · Sep 17, 2019 · Viewed 11.4k times · Source

Im using Joi library as standalone validator for my CRA project but when firing email() validator im getting cryptic error

Uncaught Error: Built-in TLD list disabled

Answer

Ahmad Khudeish picture Ahmad Khudeish · Jan 8, 2020

From Joi documentation:

By default, the TLD must be a valid name listed on the IANA registry. To disable validation, set tlds to false. To customize how TLDs are validated, set one of these:

allow - one of:

  • true to use the IANA list of registered TLDs. This is the default value.
  • false to allow any TLD not listed in the deny list, if present.
  • a Set or array of the allowed TLDs. Cannot be used together
    with deny.

To disable TLD validation against IANA accepted list:

email: Joi.string().email({ tlds: { allow: false } });

This should disable the validation and allow you to accept any TLD even if it's not IANA registered.