Spec-Zone.ru › Valibot

email

Creates an email validation action.

const Action = v.email<TInput, TMessage>(message);

Generics

  • TInput extends string
  • TMessage extends ErrorMessage<EmailIssue<TInput>> | undefined

Parameters

  • message TMessage

Explanation

With email you can validate the formatting of a string. If the input is not an email, you can use message to customize the error message.

This validation action intentionally only validates common email addresses. If you are interested in an action that covers a broader subset of RFC 5322 addresses, please use the rfcEmail action instead.

Returns

  • Action EmailAction<TInput, TMessage>

Examples

The following examples show how email can be used.

Email schema

Schema to validate an email.

const EmailSchema = v.pipe(
  v.string(),
  v.nonEmpty('Please enter your email.'),
  v.email('The email is badly formatted.'),
  v.maxLength(30, 'Your email is too long.')
);

Optional email schema

Schema to validate an email that is allowed to be an empty string, for example for an optional form field.

const OptionalEmailSchema = v.optional(
  v.union([
    v.literal(''),
    v.pipe(v.string(), v.email('The email is badly formatted.')),
  ]),
  ''
);

Related

The following APIs can be combined with email.

Schemas

any, custom, string

Methods

pipe

Utils

isOfKind, isOfType

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/email/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API