Add Pattern Validation in Wix: What a Regex Rule Checks and Where It Breaks
How regex pattern validation works on Wix form fields, which fields suit it, how pasted and Unicode-styled text can fail it, and when free text is the better choice.
Pattern validation on a Wix form field checks what a visitor typed against a regular expression and blocks submission when the value does not match. It is useful for structured data and can frustrate visitors when applied to fields that vary naturally. This review explains what the rule does and does not change, which fields suit it, and how copied, pasted or Unicode-styled text affects it. No verified test of Wix's current editor menus was available for this review, so Wix-specific steps are described in general terms. Confirm exact settings and API names against Wix's current documentation before relying on them.
Is pattern validation the right fit for your field?
Use a regex rule when the field has a fixed format that you define and control, such as an internal order code, a SKU, a membership number or a single-country postal code. The main benefit is that typos are caught before submission, so the data arrives in a consistent shape. The decisive tradeoff is that any legitimate input you did not anticipate is rejected, and the visitor may give up rather than guess what the form wants. Plain free text without a pattern is preferable for names, street addresses, international phone numbers, comments, and any field where a person can correct an odd entry later at little cost.
| Field | Pattern validation suitability | Main risk |
| Internal code you issue (e.g. AB-1234) | Good fit | Low, if the format is documented on the form |
| Single-country postal code | Reasonable fit | Rejects visitors from other countries |
| Email address | Light check only | Strict email regexes reject valid addresses |
| International phone number | Usually a poor fit | Spaces, plus signs and varied lengths are all legitimate |
| Personal name | Poor fit | Apostrophes, hyphens, accents and non-Latin scripts get rejected |
| Free-form comment | Not appropriate | Nothing to validate structurally |
What pattern validation actually changes
A validation rule does not change the text. It is a test, not a transformation: it does not reverse characters, mirror glyphs, substitute Unicode lookalikes or apply formatting. Its only output is accept or reject, plus an error message. If you also want to alter the stored value, such as trimming spaces or converting to uppercase, that is a separate step you must add yourself. Validating a cleaned-up copy of the input does not clean up the value that gets submitted.
"Pattern" here means a regular expression, not a visual pattern, font or text style. The matching rules depend on where the expression runs. The HTML pattern attribute is matched against the whole value, as if wrapped in start and end anchors. A regular expression tested in your own JavaScript is not anchored automatically, so an unanchored expression like [A-Z]{2} will pass any value that merely contains two capital letters. Add ^ at the start and $ at the end when you mean the entire field.
Where the rule lives in Wix
Wix offers two general routes. The first is the field's own settings in the editor, which typically cover input type, required status and length limits. Whether a direct regex option appears there depends on the editor and form type, and this was not verified for this review. The second is code through Wix's developer platform (Velo), which documents a custom validation hook on input elements. In that hook your function receives the value and a reject callback. The example below uses that approach; the element ID is a placeholder for your own field's ID.
const codePattern = /^[A-Z]{2}-\d{4}$/;
$w.onReady(() => {
$w("#orderCode").onCustomValidation((value, reject) => {
const cleaned = value.normalize("NFC").trim();
if (!codePattern.test(cleaned)) {
reject("Enter a code like AB-1234: two capital letters, a hyphen, four digits.");
}
});
});
The expression is anchored at both ends, so extra characters before or after the code cause a rejection. The function tests a normalized, trimmed copy of the input, but as noted above, the submitted value is still exactly what the visitor entered. The rejection message states the expected format in words rather than echoing the regex, because visitors cannot be expected to read regular expressions.
Testing the expression before you publish
- A value that should pass, typed by hand
- The same value with a leading or trailing space
- The same value pasted from a spreadsheet, email or PDF
- Lowercase letters where uppercase is expected, if you intend to accept or reject them deliberately
- A value with an extra character at the end, to confirm the anchors work
- An empty field, to confirm how required status and the pattern interact
- Any accented or non-Latin input a real visitor might plausibly enter
Will input still pass after copying and pasting?
Pasted text is the most common source of unexpected rejections. A value can look identical on screen and still fail, because the characters underneath differ from what was typed. Styled "fancy font" text from online generators uses separate Unicode code points, such as mathematical alphanumeric symbols, that only look like ordinary letters. A pattern like [A-Za-z] will not match them, and they also hurt search and screen reader output wherever the text ends up.
- Non-breaking spaces (U+00A0) copied from web pages or word processors; \s matches them in JavaScript, but a literal space in your pattern does not
- Zero-width characters (such as U+200B) that are invisible but break exact matches
- Fullwidth digits and letters, which \d and [A-Z] do not match in JavaScript
- Curly quotes and typographic dashes in place of straight quotes and hyphens
- Unicode-styled lookalike letters from text-styling tools
Accented letters can be stored in two ways: as one precomposed character, or as a base letter followed by a combining mark. Normalizing to NFC before testing, as in the example, makes both forms compare the same way. If you use Unicode property classes such as \p{L} to accept letters from any script, the expression needs the u flag in JavaScript. Length limits deserve similar care, because JavaScript's string length counts UTF-16 code units: an emoji built from several code points, such as a family or flag emoji, can count as several characters even though it displays as one.
Accessibility of validation errors
WCAG 2 success criteria 3.3.1 (Error Identification) and 3.3.3 (Error Suggestion) call for errors to be described in text and, where possible, to say how to fix the input. State the expected format in the field label or help text before the visitor types, not only after a failure, and do not rely on a red border alone. How Wix exposes custom validation messages to assistive technology was not tested for this review. Check your published form with the screen readers your audience uses rather than assuming one correct rendering holds everywhere.
Validation is not a security control
Checks that run in the visitor's browser improve data quality, but they can be bypassed by anyone who submits data directly. If a value feeds into anything sensitive, such as database queries, automations, pricing or access decisions, validate it again on the server side before trusting it. Treat the browser-side pattern as a convenience for honest visitors, not as protection against malicious input.