Schema - MaxLength (String)
The .maxLength
method is used to validate whether a given string does not exceed a specified maximum length. It ensures that the input string contains no more than the allowed number of characters, providing a way to enforce upper length constraints on user input or other string-based data.
This method is particularly useful in scenarios where overly long strings might cause issues, such as database storage, user interface limitations, or specific data validation rules.
Example
Below is an example of how to use .maxLength
to validate whether a string respects the maximum length:
import { schema } from "vkrun"
const schexampleSchemaema = schema().string().maxLength(5)
const validateA = exampleSchema.validate("12345")
const validateB = exampleSchema.validate("123456")
console.log(validateA) // true
console.log(validateB) // false