Schema - MinLength (String)
The .minLength
method is used to validate whether a given string meets the minimum length requirement. It ensures that the input string contains at least the specified number of characters, providing a way to enforce length constraints on user input or other string-based data.
This method is particularly useful in scenarios where a minimum character count is critical, such as password fields, usernames, or any input where shorter values might be invalid.
Example
Below is an example of how to use .minLength
to validate whether a string meets the required length:
import { schema } from "vkrun"
const exampleSchema = schema().string().minLength(5)
const validateA = exampleSchema.validate("12345")
const validateB = exampleSchema.validate("1234")
console.log(validateA) // true
console.log(validateB) // false