Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOI email validation

Tags:

hapijs

joi

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

like image 475
Konrad Albrecht Avatar asked Sep 17 '19 10:09

Konrad Albrecht


People also ask

What is minDomainSegments?

minDomainSegments - the minimum number of domain segments (e.g. x.y.z has 3 segments) required in the domain part. Defaults to 2 . tlds - options to validate the top-level-domain segment (e.g. com in example.com ) where: deny - a Set with strings matching forbidden TLD values (all non-matching values are allowed).


1 Answers

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.

like image 51
Ahmad Khudeish Avatar answered Jan 27 '23 14:01

Ahmad Khudeish