string
Создаёт схему строки.
const Schema = v.string<TMessage>(message);
Обобщения
TMessageextends ErrorMessage<StringIssue> | undefined
Параметры
messageTMessage
Пояснение
С помощью string можно проверить тип данных входного значения. Если входное значение не является строкой, используйте message, чтобы настроить сообщение об ошибке.
Возвращаемое значение
SchemaStringSchema<TMessage>
Примеры
В следующих примерах показано, как можно использовать string.
Схема электронной почты
Схема для проверки адреса электронной почты.
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.')
);
Схема пароля
Схема для проверки пароля.
const PasswordSchema = v.pipe(
v.string(),
v.minLength(8, 'Your password is too short.'),
v.maxLength(30, 'Your password is too long.'),
v.regex(/[a-z]/, 'Your password must contain a lowercase letter.'),
v.regex(/[A-Z]/, 'Your password must contain a uppercase letter.'),
v.regex(/[0-9]/, 'Your password must contain a number.')
);
Схема URL
Схема для проверки URL.
const UrlSchema = v.pipe(
v.string('A URL must be string.'),
v.url('The URL is badly formatted.')
);
Связанные элементы
Следующие API можно использовать вместе с string.
Схемы
array, exactOptional, intersect, lazy, looseObject, looseTuple, map, nonNullable, nonNullish, nonOptional, nullable, nullish, object, objectWithRest, optional, record, set, strictObject, strictTuple, tuple, tupleWithRest, undefinedable, union
Методы
assert, config, fallback, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser
Действия
base64, bic, brand, bytes, codePoints, creditCard, cuid2, check, decimal, description, digits, domain, email, emoji, empty, endsWith, excludes, flavor, graphemes, gtValue, guard, hash, hexadecimal, hexColor, imei, includes, ip, ipv4, ipv6, isbn, isrc, isoDate, isoDateTime, isoDateTimeSecond, isoTime, isoTimeSecond, isoTimestamp, isoWeek, ksuid, length, ltValue, mac, mac48, mac64, maxBytes, maxCodePoints, maxGraphemes, maxLength, maxValue, maxWords, metadata, minBytes, minCodePoints, minGraphemes, minLength, minValue, minWords, nanoid, nonEmpty, notBytes, notCodePoints, notEntries, notGraphemes, notLength, notValue, notValues, notWords, octal, parseJson, rawCheck, rawTransform, readonly, regex, rfcEmail, slug, startsWith, stringifyJson, title, toBigint, toBoolean, toCamelCase, toDate, toKebabCase, toLowerCase, toMaxValue, toMinValue, toNumber, toPascalCase, toSnakeCase, toUpperCase, transform, trim, trimEnd, trimStart, ulid, url, uuid, value, values, words
Утилиты
entriesFromList, isOfKind, isOfType
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/string/