ProtectedisWhether the schema requires a non-null/non-undefined value.
Sets the requirement flag. Must be a boolean.
ProtectedpreprocessorsA list of preprocessors associated with the Builder
ProtectedtypeThe string identifier of the schema type (e.g. 'string', 'number', 'object').
Sets the schema type identifier. Must be a non-empty string.
ProtectedvalidatorsA list of validators associated with the Builder
Adds a preprocessor to a preprocessors list
ProtectedassureEnsures a ValidationErrorMessageProvider is valid.
If provider is undefined, falls back to defaultValue.
Function providers are bound to this for access to schema state.
the provider to validate, or undefined
fallback provider when provider is not supplied
a valid ValidationErrorMessageProvider
Cancels endsWith() call.
Cancels equals() call.
Clears type set by call to .hasType<T>(), default schema type inference will be used
for schema returned by this call.
Cancels matches() call.
Cancel maxLength() call.
Cancel minLength() call.
Remove all preprocessors for this schema.
Cancels startsWith() call.
Remove all validators for this schema.
ProtectedcreateRestricts string to end with val.
OptionalerrorMessage: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>Custom error message provider.
Restricts string to be equal to value.
OptionalerrorMessage: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>Custom error message provider.
ProtectedgetResolves a ValidationErrorMessageProvider to a string error message.
Handles both string providers and function providers (sync or async).
the error message provider (string or function)
the value that caused the validation error
the resolved error message string
Set type of schema explicitly. notUsed param is needed only for case when JS is used. E.g. when you
can't call method like schema.hasType<Date>(), so instead you can call schema.hasType(new Date())
with the same result.
Optional_notUsed: TGenerates a serializable object describing the defined schema
If set, restrict string to end with a certain value.
Ends with validation error message provider. If not provided, default error message will be used.
If set, restrict object to be equal to a certain value.
Equals validation error message provider. If not provided, default error message will be used.
If set to false, schema will be optional (null or undefined values
will be considered as valid).
If set, restrict string to match a certain regular expression.
Matches validation error message provider. If not provided, default error message will be used.
Max length of the string (if defined).
Max length validation error message provider. If not provided, default error message will be used.
Min length of the string (if defined).
Min length validation error message provider. If not provided, default error message will be used.
Array of preprocessor functions
Custom error message provider for the 'is required' validation error.
If set, restrict string to start with a certain value.
Starts with validation error message provider. If not provided, default error message will be used.
String id of schema type, e.g. string', numberorobject`.
Array of validator functions
Restricts string to match regexp.
regular expression pattern to match against
OptionalerrorMessage: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>Custom error message provider.
Set maximal length of the valid value for schema.
maximum string length
OptionalerrorMessage: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>Custom error message provider.
Set minimal length of the valid value for schema.
minimum string length
OptionalerrorMessage: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>Custom error message provider.
ProtectedpreRuns preprocessors, validators, and the required/optional check on object.
Subclasses call this at the start of their validate() implementation to get
a preprocessed value wrapped in a transaction, along with any early errors.
the value to pre-validate
Optionalcontext: ValidationContext<SchemaBuilder<any, any>>optional validation context settings
a PreValidationResult containing the preprocessed transaction, context, and any errors
Restricts string to start with val.
OptionalerrorMessage: ValidationErrorMessageProvider<StringSchemaBuilder<TResult, TRequired>>Custom error message provider.
Performs validation of string schema over object.
Optionalcontext: ValidationContextOptional ValidationContext settings.
Allows to define a schema for a string. It can be: required or optional, restricted to be equal to a certain value, restricted to have a certain length, restricted to start with a certain value, restricted to end with a certain value, restricted to match a certain regular expression.
NOTE this class is exported only to give opportunity to extend it by inheriting. It is not recommended to create an instance of this class directly. Use string() function instead.
Example: ```ts const schema = string().equals('hello'); const result = await schema.validate('hello'); // result.valid === true // result.object === 'hello' ```
Example: ```ts const schema = string().equals('hello'); const result = await schema.validate('world'); // result.valid === false // result.errors[0].message === "is expected to be equal to 'hello'" ```
Example: ```ts const schema = string().minLength(5); const result = await schema.validate('hello'); // result.valid === true // result.object === 'hello' ```
Example: ```ts const schema = string().minLength(5); const result = await schema.validate('hi'); // result.valid === false // result.errors[0].message === 'is expected to have a length of at least 5' ```
Example: ```ts const schema = string().minLength(2).maxLength(5); const result = await schema.validate('yes'); // result.valid === true // result.object === 'yes' ```
Example: ```ts const schema = string('no'); const result = await schema.validate('yes'); // result.valid === false // result.errors[0].message === "is expected to be equal to 'no'" ```
See
string