Skip to main content

Try it Live

Run ENS examples in the interactive playground

ENS Validation

The Ens module has three checks. They answer different questions: isValid() and validate() run full ENSIP-15 normalization. is() does not; it is a cheap type guard.

isValid(name)

Returns true if name is a non-empty string that normalizes without error. Returns false for empty strings, non-strings, and names that fail normalization.
isValid() returns true for names that are valid but not yet normalized, such as "VITALIK.eth". It does not tell you the name is canonical. Use normalize() to get the canonical form.

validate(name)

Same rules as isValid(), but throws instead of returning false.
Every failure throws DisallowedCharacterError with docsPath set to /primitives/ens/validate:
  • Empty or non-string input: no cause; value is String(name).
  • Normalization failure: cause is the @adraffy/ens-normalize error, whose message names the rule that failed.
See Errors for all error fields.

is(value)

Returns true when value is a string with length greater than zero. It does not check characters, labels, or normalization.
Use is() to narrow unknown input to the Ens type. Do not use it as a security check. See Branded Ens.

Validate or normalize?

validate() and normalize() run the same ENSIP-15 algorithm. If you need the canonical name anyway, call normalize() once and handle its error instead of calling both:
The explicit empty check is needed because normalize("") returns "" without throwing.

Rules enforced

All rules come from ENSIP-15 as implemented by @adraffy/ens-normalize. Observed failure reasons include: The module does not enforce a maximum label or name length.

See Also