Regex Patterns offer a much more complex pattern-matching approach.
They allow you to specify precise rules that determine whether entered data is considered valid or not, and whether the form can be submitted.
If the pattern rules are not met, the form will not be considered valid, and most browsers will refuse to submit it.
WARNING: Regex syntax is very picky and can be difficult to code and debug, but a good regex is hugely helpful in validating your inputs.
Which Input Types Support Patterns
To my knowledge, only a few input types make sense with patterns;
- text
- url
However you should research this yourself if you want to explore other types. Make sure to test across browsers if you're doing something unusual, like trying to force time inputs in military format.
Using in Webflow
Webflow does not provide direct designer support for patterns, however you can add them easily through custom attributes.
- Select the INPUT field you want the pattern on
- Add a custom attribute of pattern
- As the value, give the regex value you want
Notes;
- Usually, you do not need the start and end anchors in the regex string, since this is automatically assumed by the browser.
- The regex string must be encoded for use in an HTML attribute before it can be pasted into the Webflow designer. Webflow does not encode the custom value for you.
Controlling the Error Message
When a pattern rule is not met, the browser will display its own error message, however, most browsers will also display the title of the input field for added context.
Choose a message that describes valid input, and apply it as a custom attribute, e.g.;
title = Enter a valid US zip code
Nov-2022 - Webflow does not offer direct designer support for setting the title attribute, but currently allows creation of the title attribute in custom attributes.
FAQs
Answers to frequently asked questions.