Const
Combine multiple validators
const validator = Validation.combine( Validation.rule<string>("required"), Validation.rule<string>("email"), Validation.rule<string>("maxLength:100")) Copy
const validator = Validation.combine( Validation.rule<string>("required"), Validation.rule<string>("email"), Validation.rule<string>("maxLength:100"))
Create a custom validator
const isEven = Validation.custom<number>( (value) => typeof value === "number" && value % 2 === 0, "must be an even number") Copy
const isEven = Validation.custom<number>( (value) => typeof value === "number" && value % 2 === 0, "must be an even number")
Validate a form with multiple fields
const schema = { name: Validation.rule<string>("required"), email: Validation.rule<string>("email"), age: Validation.rule<number>("min:18")}const result = Validation.form(schema, { name: "John", email: "john@example.com", age: 25 }) Copy
const schema = { name: Validation.rule<string>("required"), email: Validation.rule<string>("email"), age: Validation.rule<number>("min:18")}const result = Validation.form(schema, { name: "John", email: "john@example.com", age: 25 })
Create a validator from a rule string
const validator = Validation.rule<number>("min:18")const result = validator(25) // Right(25)const error = validator(15) // Left(TypedError) Copy
const validator = Validation.rule<number>("min:18")const result = validator(25) // Right(25)const error = validator(15) // Left(TypedError)
Common pre-built validators
Combine multiple validators