Docsfrontbacked.js reference
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.

    js

    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:

    js

    Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

    Useful schema keys:

    KeyPurpose
    typestring, email, number, boolean, object, array, file, datetime, or post.
    requiredRequire a present value. Empty strings, empty arrays, and missing files fail.
    trim, lowercase, uppercaseNormalize string values before validation returns. email lowercases by default.
    min, maxString length, number value, or array length limit.
    patternRegular expression for string values.
    enumAllowed values.
    sameAsRequire the value to equal another state path.
    acceptedRequire a boolean value to be true, useful for terms checkboxes.
    maxSizeMaximum file size in bytes.
    mimeTypesAllowed file MIME types.
    maxDurationSecondsMaximum prepared video playback duration in seconds.
    fieldsNested object schema.
    of or itemsArray item schema.
    messagesOptional messages by failed rule, such as required, min, email, sameAs, accepted, maxSize, or mimeTypes.
    feedbackMessage destination options. Omit for automatic inline placement, or use { to: "alert" }, { to: "toast", duration: 4000 }, { to: "formErrors" }, or { to: "showFormError()" }.
    validateCustom validation function that receives (value, state). Return false or a string message to fail.
    allowFalseTreat boolean false as valid.
    allowEmptyStringTreat an empty string as valid.
    allowEmptyArrayTreat 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.