Form & Validation

useValidation

Input validation with custom rules, real-time feedback, and error messages.

import { useValidation } from "saha-ui"

Uses

General validation utilities for form values with rules (required, min/max length, pattern, custom) and helpers to validate single fields or the full form.

Props

NameTypeDescriptionDefault
rulesRecord<string, any>Object mapping field names to rule sets (required, minLength, maxLength, pattern, custom).-
optionsobjectBehavior options such as validation mode (e.g. onChange or onBlur).-

Returns

NameDescription
errorsCurrent error map keyed by field name.
touchedMap of touched fields.
validate(values)Validate all fields and return { isValid, errors } while updating internal state.
validateSingle(name, value)Validate a single field by name and value.
clearErrors / clearError(name)Clear all errors or a specific field error.
setTouchedField(name, touched)Mark a field as touched/untouched.

Example

const { errors, validate } = useValidation({ email: { required: true, pattern: { value: /@/, message: 'Invalid' } } }); const result = validate({ email: 'a' });

Notes

Returns error messages as strings; supports custom validators returning boolean or message.
Saha UI - The Modern React Component Library