Validation Patterns
Total CMS provides built-in validation patterns that can be used in form fields:
{{ cms.form.text('my-field', {}, { pattern: patterns.domain, help: 'Please enter a valid domain name'}) }}Available Patterns
Section titled “Available Patterns”patterns.alphaNumeric # Letters and numbers onlypatterns.notBlank # Cannot be emptypatterns.passwordUpperLowerNumber # Must contain uppercase, lowercase, and numberpatterns.date # Date formatpatterns.time # Time formatpatterns.dateTime # Date and time formatpatterns.integer # Whole numbers onlypatterns.decimal # Decimal numberspatterns.hex # Hexadecimal valuespatterns.domain # Domain namepatterns.slug # URL-friendly slugpatterns.uuid # UUID formatpatterns.macAddress # MAC addresspatterns.isbn # ISBN numberpatterns.currency # Currency formatpatterns.latitudeLongitude # Coordinatespatterns.html # HTML contentpatterns.version # Three-part version (3.5.0)patterns.versionExtended # Full semver (v3.5.1-rc.1, 3.5.0+build.7)Post Code Patterns
Section titled “Post Code Patterns”patterns.postCode.australiapatterns.postCode.austriapatterns.postCode.belgiumpatterns.postCode.brazilpatterns.postCode.canadapatterns.postCode.germanypatterns.postCode.hungarypatterns.postCode.italypatterns.postCode.japanpatterns.postCode.luxembourgpatterns.postCode.netherlandspatterns.postCode.polandpatterns.postCode.spainpatterns.postCode.swedenpatterns.postCode.ukpatterns.postCode.usaPhone Patterns
Section titled “Phone Patterns”patterns.phone.usapatterns.phone.ukpatterns.phone.francepatterns.phone.internationalUsing These in Schema Validation
Section titled “Using These in Schema Validation”The same patterns work in a schema. In a property’s Extra Schema
Definitions, set pattern to the pattern’s name:
{ "pattern": "patterns.version" }On save this expands to the real regex, anchored:
{ "pattern": "^\\d+\\.\\d+\\.\\d+$" }Nested patterns use their dotted path, exactly as in Twig:
{ "pattern": "patterns.phone.usa" }{ "pattern": "patterns.postCode.uk" }Prefer this over pasting a regex. It is shorter, it keeps the form field and the schema on one definition, and there are no backslashes to escape.
Why the expansion adds anchors
Section titled “Why the expansion adds anchors”The patterns above are stored unanchored, because an HTML pattern
attribute is anchored by the browser automatically.
JSON Schema’s pattern is a substring match instead, so a bare
\\d+\\.\\d+\\.\\d+ would accept junk-3.5.0-junk. The expansion wraps
^ and $ so a schema and a form field sharing one pattern agree on what
they accept.
- A literal regex is left alone. Anything not starting with
patterns.is stored as typed — that is the escape hatch if you want unanchored matching. - An unknown name is an error.
patterns.verisonfails on save rather than being stored as a literal regex, which would compile fine and reject every value. passwordMinLength(8)is not available in a schema. Dynamic patterns are methods, not stored values, so they work only in Twig.notBlankmeans “no whitespace anywhere”, not “not empty” — anchored,\S+rejectshello world. UseminLengthfor a not-empty check.
Dynamic Patterns
Section titled “Dynamic Patterns”patterns.passwordMinLength(8) # Minimum password length