Start page / Template development / Rules / Comparative expressions / <MATCHES/>

<MATCHES/>: Validation with regular expressions

The <MATCHES/> tag can be used in the value determination area of the rule definition (or for the definition of a precondition) and is used to enter a regular expression in a rule.

A comparison value that refers to a particular property of the form element (such as the value of the input component) or even of the form (“In which language should the form be opened?”) must be specified in the <MATCHES/> tag. To do this, a <PROPERTY/> tag must be entered within the <MATCHES/> section.

If the comparison value fulfills the conditions of the regular expression, the <MATCHES/> section returns TRUE; if not, it returns FALSE.

"regex" attribute

The regular expression is passed via the “regex” attribute. Depending on the regular expression, certain characters, strings and sequences of characters occurring in the comparison value are reviewed and evaluated.

<MATCHES regex="ABC" />

For information about the syntax which can be used for the “regex” attribute please see http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html.

Important The behavior of the “regex” attribute may slightly differ in SiteArchitect and in ContentCreator because of different regex engines.
Important Characters that are to be used for the “regex” attribute and have a special meaning in XML syntax must be masked, e.g.
- the character < must be replaced with &lt;
- the character & must be replaced with &amp;
- the character " must be replaced with &quot;

Examples

1) Language-dependent validation

In the following example, only a certain branch of the rule is carried out depending on the editing language currently being processed. The “st_standard” input component, for which the rule is defined, permits the language-dependent specification of a DIN standard (for German (“DE”)) or an ISO standard (for English (“EN”)). Using the definition of a precondition, the rule checks the language in which the form is being edited by the editor (language-dependent validation).

A different regular expression is defined within the rule for both languages. The expression checks whether the editor's input is valid for this language.

<RULES>

<RULE>
<IF>
<EQUAL>
<PROPERTY source="#global" name="LANG"/>
<TEXT>DE</TEXT>
</EQUAL>
</IF>
<WITH>
<MATCHES regex="^DIN\ \d\d*$">
<PROPERTY source="st_standard" name="VALUE"/>
</MATCHES>
</WITH>
<DO>
<VALIDATION scope="SAVE">
<PROPERTY source="st_standard" name="VALID"/>
<MESSAGE lang="*" text="No DIN standard given"/>
<MESSAGE lang="DE" text="Keine DIN-Norm angegeben"/>
</VALIDATION>
</DO>
</RULE>

<RULE>
<IF>
<NOT>
<EQUAL>
<PROPERTY source="#global" name="LANG"/>
<TEXT>DE</TEXT>
</EQUAL>
</NOT>
</IF>
<WITH>
<MATCHES regex="^ISO\ \d\d*$">
<PROPERTY source="st_standard" name="VALUE"/>
</MATCHES>
</WITH>
<DO>
<VALIDATION scope="SAVE">
<PROPERTY source="st_standard" name="VALID"/>
<MESSAGE lang="*" text="No ISO standard given"/>
<MESSAGE lang="DE" text="Keine ISO-Norm angegeben"/>
</VALIDATION>
</DO>
</RULE>

</RULES>

2) Preventing white spaces

For some text input components (e.g., CMS_INPUT_TEXT), white spaces (including blank spaces) count as content (similar to the “allowEmpty” parameter), i.e., a text input component is even classed as “not empty” if just one or more blank spaces are entered. If entries consisting solely of white spaces are to be prevented, this check can be performed using regular expressions:

<RULES>
<RULE>
<WITH>
<NOT>
<MATCHES regex="^\s*$">
<PROPERTY name="VALUE" source="st_headline"/>
</MATCHES>
</NOT>
</WITH>
<DO>
<VALIDATION scope="SAVE">
<PROPERTY name="VALID" source="st_headline"/>
<MESSAGE lang="*" text="No content provided!"/>
<MESSAGE lang="DE" text="Es wurde kein Inhalt erfasst!"/>
</VALIDATION>
</DO>
</RULE>
</RULES>

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.12 | Data privacy