"US Phone" and "US Zip Code" regex-validation presets are malformed — causes unhandled exception on save
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 970
- Forks
- 486
- Avg merge
- 3d 33m
- Merged PRs (30d)
- 170
Description
Summary
The built-in "US Phone" preset for a field's Regex Validation property is malformed — it is missing escape backslashes and is not valid regex syntax in either JavaScript or Java. As a result, phone-number validation using this preset does not work as intended, and saving a contentlet through the legacy Edit Content screen throws an unhandled server-side exception instead of a normal validation error.
Where the bug is
core-web/apps/dotcms-ui/src/app/portlets/shared/dot-content-types-edit/components/fields/content-type-fields-properties-form/field-properties/regex-check-property/regex-check-property.component.ts:68
value: '^(?[1-9]d{2}[)-]s?d{3}-d{4}$'
Every \d, \s, \(, \) is missing its backslash. The correct pattern is:
^\(?[1-9]\d{2}[\)-]\s?\d{3}-\d{4}$
The "US Zip Code" preset in the same file (line 62) has the identical defect:
value: '(^d{5}$)|(^d{5}-d{4}$)'
Steps to reproduce
- Create (or edit) a Text field on a Content Type.
- Set Regex Validation to the "US Phone" preset.
- Edit a contentlet using that field via the legacy (non-UVE) Edit Content screen.
- Enter a value, e.g.
123-4567, and Save.
Actual behavior
- No client-side validation fires at all. In
edit_field.jsp:184, dojo'sdijit.form.ValidationTextBox(which wires up a client-sideregExp) is only applied to Number/Float/Hostname field types — a plain Text field with a custom Regex Validation preset renders as a plaindijit.form.TextBoxwith no client-side check. - Enforcement happens only server-side, on Save, in
ESContentletAPIImpl.validateContentlet(dotCMS/src/main/java/com/dotcms/content/elasticsearch/business/ESContentletAPIImpl.java:8250-8271), viaPattern.matches(regext, s)with no surrounding try/catch. - Because the "US Phone" string itself is invalid regex syntax,
Pattern.matchesthrows an uncheckedjava.util.regex.PatternSyntaxException:
(Verified directly by running the exact string throughjava.util.regex.PatternSyntaxException: Unknown inline modifier near index 3 ^(?[1-9]d{2}[)-]s?d{3}-d{4}$ ^java.util.regex.Pattern.matchesin a standalone JDK 11 test.) This exception is unchecked and uncaught, so it escapesvalidateContentlet(which only declaresthrows DotContentletValidationException) as an unhandled runtime exception — instead of the normal, friendly "field does not match pattern" validation message (DotContentletValidationException.Builder#addPatternField) that a correctly-formed regex would produce. - The same malformed string also fails to compile as a JavaScript
RegExp(new RegExp('^(?[1-9]d{2}[)-]s?d{3}-d{4}$')throwsSyntaxError: Invalid regular expression: ... Invalid group), so any newer editor surface that constructs the pattern client-side (e.g. Angular reactive-form validators) also fails to apply real validation for this preset.
Expected behavior
Entering a value that doesn't match a valid US phone number format should show a normal, graceful field-validation error — not an unhandled exception.
Confirmed workaround / fix
Manually editing the field's regexCheck value to the correctly-escaped pattern:
^\(?[1-9]\d{2}[\)-]\s?\d{3}-\d{4}$
resolves the issue — the field validates phone numbers correctly with no exception.
Suggested fix
- Correct the "US Phone" and "US Zip Code" preset regex strings in
regex-check-property.component.tsto include the proper escape backslashes. - Wrap
Pattern.matches(regext, s)inESContentletAPIImpl.validateContentletwith a catch forPatternSyntaxException, so that any malformed regex (built-in preset or custom) produces a graceful field validation error instead of an unhandled exception on save.
Environment
- dotCMS version: 26.08.19-04
- Confirmed against current
dotCMS/coremain branch source (as of 2026-08-21).
Relevant links.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in core-web/apps/dotcms-ui/src/app/portlets/shared/dot-content-types-edit/components/fields/content-type-fields-properties-form/field-properties/regex-check-property/regex-check-property.component.ts, then inspect edit_field.jsp and ESContentletAPIImpl.validateContentlet. Verify the preset strings in JavaScript and Java, and reproduce the save path with the legacy Edit Content screen. Done means both presets compile and invalid patterns produce a normal field-validation error rather than an unhandled exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- backend, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100