StringSchema
Validates strings. Every refinement returns a new schema, so a base schema can be shared and specialised without being modified.
local Base = v.string()
local Username = Base:min(3):max(22)
Properties
minimum
This item is read only and cannot be modified. Read OnlyReflectionStringSchema.minimum: number?
Shortest length this schema accepts, or nil if it is unbounded. Set by
StringSchema:min and StringSchema:length.
maximum
This item is read only and cannot be modified. Read OnlyReflectionStringSchema.maximum: number?
Longest length this schema accepts, or nil if it is unbounded. Set by
StringSchema:max and StringSchema:length.
isOptional
This item is read only and cannot be modified. Read OnlyReflectionStringSchema.isOptional: boolean
Always false. Reading it on any schema tells you whether nil is
accepted without having to know which kind of schema you hold.
access
This item is read only and cannot be modified. Read OnlyReflectionStringSchema.access: "readwrite"
Always "readwrite". Chain StringSchema:readonly or
StringSchema:writeonly to change it.
Functions
_validate
ParsingStringSchema:_validate(value: unknown) → Result<string>
Validates value without throwing. All refinements run, so the returned
issues describe every failure rather than only the first.
parse
ParsingStringSchema:parse(value: unknown) → stringValidates value and returns it, throwing on failure.
Errors
| Type | Description |
|---|---|
| "expected ..." | Thrown when `value` fails validation |
min
RefinementRequires the string to be at least n characters long.
max
RefinementRequires the string to be at most n characters long.
length
RefinementRequires the string to be exactly n characters long.
optional
WrapperWraps this schema so that nil is also accepted.
default
WrapperWraps this schema so that nil yields fallback instead of failing.
defaultWith
WrapperStringSchema:defaultWith(produce: () → string--
Builds the value used when parsing nil
) → DefaultSchema<string>
Like StringSchema:default, but calls produce on every parse instead of
reusing one value. Use it when the fallback is a table, since a single
table would otherwise be shared by every caller and mutable through any
of them.
The produced value is validated each time, so a producer that returns something invalid fails at parse rather than silently passing through.
readonly
WrapperWraps this schema so that a field using it is typed read.
writeonly
WrapperWraps this schema so that a field using it is typed write.