Superform by Delta Clan
✨ ClonablesSocialResourcesSuperform Home
v2
v2
  • 🏁Getting Started
    • Introduction
    • Quick Start
  • 🫀Essentials
    • Form Container
    • Step Container
    • Navigation - Overview
      • Direct
      • Logic / Conditional
      • Hook
    • Variables
      • Form Data ($f)
      • Step Index ($s)
      • Progress Percentage ($p)
      • Scoring Variables ($v)
    • Progress Bar
    • Reset
    • Radio Groups
    • Checkbox Groups
    • Cheatsheet
  • ⚙️Global Options
    • Step Delay Controls
    • Animations
      • Step Animation
      • Step Animation Duration
      • Step Animation Ease
    • Save Data & Progress
    • Pre-fill Form
    • Prevent Content Flash
    • Debug
    • Third-party Integrations
    • Cheatsheet
  • 🎛️Input Validation & Errors
    • Validation
      • length()
      • words()
      • minmax()
      • checkbox()
      • must()
      • hook()
    • Error Management
      • Automatic Error Setup
      • Manual Error Setup
  • ⚡Reactivity
    • Update Text
    • Visibility
    • Class Toggle
    • Value
    • Set Attribute
  • 🔢Score Tracking
    • Score Setup & Calculation
    • Score Ranking
  • ⌨️Accessibility
    • Enter & Backspace Bindings (↩, ⌫)
    • Checkbox & Radio Bindings
  • 🛠️Javascript SDK
    • Intro to Superform API
    • Superform Instance
    • Cheatsheet
  • 📖Additional Resources
    • WTF is an expression ? 🆕
    • Integrations
    • Tutorials
    • Changelog
    • FAQ 🚧
    • Join Discord
Powered by GitBook
On this page
  • Setup
  • Usage Examples
  • Attribute Configuration

Was this helpful?

  1. Input Validation & Errors
  2. Validation

words()

Ensure the input contains a specific range of words.

Setup

Attribute: sf-validation="words(MIN_WORDS, MAX_WORDS)"

Ensures that the input contains a specific range of words. This is particularly useful for fields like comments, descriptions, or any input where word count matters.

For example, you can require a user to enter between 5 and 20 words to ensure sufficient detail without overwhelming verbosity.

Please note: words() validation should be applied to the following input types: text, textarea, search, url.

HTML Example

index.html
<!-- Form Container -->
<div sf="myForm">
    <form>
        <!-- Textarea with Words Validation -->
        <div sf-step="step1">
            <label for="inputText">Enter your text:</label>
            <textarea name="inputText" id="inputText" sf-validation="words(0,3)" required></textarea>
            <div class="text-style-error">Text must be a maximum of 3 words.</div>
            <button sf-goto="next">Next</button>
        </div>
    </form>
</div>

Webflow Example


Usage Examples

  • words(0,10): Minimum of zero words are allowed, and the maximum number of words can be up to 10.

  • words(5): Minimum of 5 words are required, with no restriction on the maximum number of words.


Attribute Configuration

Make sure to add the sf-validation="words(MIN_NUM,MAX_NUM)" attribute key-pair to valid input types as mentioned above.

Here are some instructions to keep in mind:

  • The attribute value should follow the format words(MIN_NUM,MAX_NUM) or words(MIN_NUM).

  • words() validation can be paired with native HTML attributes like pattern.

Dos and Don'ts


Do ✅

  • words(2,100)

  • words(2)

Don't ❌

  • words(any,100): Don't use alphabetic characters as arguments; only numbers are allowed.

  • words(10 , 10): Don't use spaces.

  • words(2.5 ,15.5): Don't use fractional numbers.

  • words(1,2,3): Don't use more than 2 arguments.

Last updated 11 months ago

Was this helpful?

🎛️
Adding sf-validation = words(0,3) to a <textarea> element.