On this page
Validation reference
Check state and choose validation feedback.
Before you begin: Billing reference.
Validation
Frontbacked.state.check(path, schema, options?) validates one state path or a whole state object against a schema. Await its Promise to get { ok, value, submitValue, values, submitValues, errors }. Submit submitValue, which excludes browser-only fields and contains prepared images. If validation fails, Frontbacked shows messages and returns ok: false. See Schema and Validation for full examples.
Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →
The optional third argument contains settings, including a mutable check accumulator:
Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →
Useful schema keys:
| Key | Purpose |
|---|---|
type | string, email, number, boolean, object, array, file, datetime, or post. |
required | Require a present value. Empty strings, empty arrays, and missing files fail. |
trim, lowercase, uppercase | Normalize string values before validation returns. email lowercases by default. |
min, max | String length, number value, or array length limit. |
pattern | Regular expression for string values. |
enum | Allowed values. |
sameAs | Require the value to equal another state path. |
accepted | Require a boolean value to be true, useful for terms checkboxes. |
maxSize | Maximum file size in bytes. |
mimeTypes | Allowed file MIME types. |
maxDurationSeconds | Maximum prepared video playback duration in seconds. |
fields | Nested object schema. |
of or items | Array item schema. |
messages | Optional messages by failed rule, such as required, min, email, sameAs, accepted, maxSize, or mimeTypes. |
feedback | Message destination options. Omit for automatic inline placement, or use { to: "alert" }, { to: "toast", duration: 4000 }, { to: "formErrors" }, or { to: "showFormError()" }. |
validate | Custom validation function that receives (value, state). Return false or a string message to fail. |
allowFalse | Treat boolean false as valid. |
allowEmptyString | Treat an empty string as valid. |
allowEmptyArray | Treat an empty array as valid. |
When a message is missing, Frontbacked generates one from the field key and failed rule. For example, firstName becomes first name, so a missing required value becomes Please enter your first name., while min: 2 becomes First name must be at least 2 characters..
Continue with Loading attributes reference.