HTML pattern not working? Check the input and submit path
SimilarForm · Published 2026-11-29 · Updated 2026-11-29
https://www.similarform.com/resources/html-pattern-not-working
Debug an HTML pattern with a small test matrix: supported input types, full-value matching, empty fields and submission behavior.
The examples describe a fictional internal reference code, not a universal rule for names, phone numbers or postal addresses. Validate submitted data on the server as well.
Write the acceptance rule before the expression
For this example, a reference code must contain two uppercase ASCII letters followed by four digits, such as AB0042. Lowercase letters and surrounding spaces are deliberately rejected. That is a business rule for this example, not something to apply to ordinary names or international addresses.
Use the validation-pattern generator for a starting point, then test the markup that your form actually renders. A regular expression that works in a JavaScript test can still be attached to the wrong HTML control or bypassed by a custom submit flow.
Use a supported input and match the entire value
For the example, the relevant attributes are type="text", pattern="[A-Z]{2}[0-9]{4}" and required. Keep the explanation “Two uppercase letters followed by four digits, for example AB0042” visible next to the field.
The pattern attribute applies to text, search, url, tel, email and password inputs, not number inputs. HTML patterns match the entire value and are written without JavaScript slash delimiters. Browsers compile them with the Unicode v flag; an invalid expression does not impose the intended pattern constraint. Check escaping if you copy a more complicated character class. These behaviors are documented by MDN.
Keep a small regression matrix
Use the same cases in the actual browser form and in your server validation. If the results differ, record where the rule or normalization changed.
Value | Expected outcome in this example | Reason
AB0042 | Accept | Two uppercase letters and four digits
AB042 | Reject | Only three digits
ab0042 | Reject | Lowercase was not allowed by this example’s rule
AB0042X | Reject | An extra character violates the full-value rule
“ AB0042 ” (spaces) | Reject | Spaces are not part of the accepted format
Empty | Reject with required; otherwise not a pattern mismatch | Presence and shape are different constraints
Check how the form submits
Try the normal submit button with an invalid value. Check whether the form has novalidate or the submit button has formnovalidate. These opt out of the normal interactive validation step. If code calls form.submit(), native constraint validation is bypassed; requestSubmit() follows the normal submission process.
If your application sends data with a custom handler, explicitly check validity and provide understandable errors before sending. Server-side validation remains necessary because browser checks can be bypassed. A pattern is a format check, not proof that an email address belongs to someone or that a reference code exists.
For the fictional code, decide whether surrounding whitespace should be rejected or trimmed. If the real workflow allows trimming, update both the test cases and server normalization deliberately. Do not silently change the pattern until an accidental input happens to pass.
Make the error useful
Explain the accepted format near the input and connect supporting text with aria-describedby. If your form displays a custom error, identify the field and the needed correction in text; color alone is insufficient. Keep the entered value available so the person can correct it.
A helpful example message is “Enter two uppercase letters and four digits, such as AB0042.” Avoid “Invalid input,” which gives no next step. Test keyboard navigation and submission on a phone as well as a desktop. The linked accessible-errors guide goes deeper into error summaries and field-level feedback.
Use the fix in the form you are migrating
Save the input attributes, test matrix and submit-path notes with the original form. They become acceptance criteria when recreating it elsewhere. SimilarForm helps teams recreate and review forms before publishing. Sign up if that migration workflow would save you recurring work.
HTML pattern not working? Check the input and submit path — worksheet
Use the worked example as a starting point. Record your own evidence and decisions in the fields below.
Field purpose and allowed format:
____________________________________________________________
Rendered input type and pattern:
____________________________________________________________
Required or optional; whitespace policy:
____________________________________________________________
Expected passing examples:
____________________________________________________________
Expected failing and blank examples:
____________________________________________________________
Browser / device results:
____________________________________________________________
Submit button, novalidate and custom handler behavior:
____________________________________________________________
Server validation and normalization:
____________________________________________________________
Visible hint and error wording:
____________________________________________________________
Migration acceptance checks:
____________________________________________________________
Sources reviewed 2026-11-29
MDN: pattern attribute behavior: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/pattern
MDN: browser and server form validation: https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Form_validation
Continue your task
Prepare a rule with the validation-pattern generator: https://www.similarform.com/tools/validation-pattern-generator
Write accessible form errors: https://www.similarform.com/resources/accessible-form-validation-errors
Test a form migration: https://www.similarform.com/resources/form-migration-testing-checklist
Sign up: https://www.similarform.com/early-access