Skip to main content

Use pattern matching to validate fields

Log in to add to favourites

The matches pattern validation method ensures that the value of a field matches a specific pattern defined by a regular expression.

A regular expression is a special text string for describing a search pattern. We use these expressions to validate the text that an author enters into a field of an entry.

Appearance

How to set the validation

With a content type open for editing:

  1. Select the text field you want to set a validation rule for and pick the Validation tab from the Field Settings panel.
  2. Choose the required regular expression pattern you want to use from the Matches pattern dropdown, or define your own using the Custom option.
  3. You can add an alternative validation message by entering it in the Validation message text box. This will be displayed if the field fails validation when published.

Setting a custom expression

You can use the Custom option in the matches pattern dropdown to create your own. Using a handy library and expression checker, like Regular Expression 101, to test your expression makes things easier.

Note: Expressions need to be written using the full JavaScript syntax to be valid.

Predefined regular expressions

We've included some predefined expressions covering some standard scenarios.

Website address

Allowed valuesDisallowed values
http://www.zengenti.comspecial%character@zengenti.com
https://contensis.comname@zengenti
http://www.contensis.com/help-and-docs/user-guides/introduction-to-contensisnotawebsite.com

Email address

Allowed valuesDisallowed values
niceandsimple@example.comAbc.example.com
very.common@example.comA@b@c@example.com
a.little.lengthy.but.fine@dept.example.comjohn..doe@example.com

UK postcodes

Allowed valuesDisallowed values
SY8 3EGSY8_3EG
sy83egsy8-3eg
SY83EGsy8 £eg

12 hour time

Allowed valuesDisallowed values
10:20 am12:15
10.42.01 AM101603
09 26 03 PM12am
7:35 PM10:67

24 hour time

Allowed valuesDisallowed values
10:201215
10.42.01101603
09 26 0312 am
07:5710:67

Title casing

Allowed valuesDisallowed values
This Is A TitleThis is a title
This Is Another TitleThis is A title

Still need help?

If you still need help after reading this article, don't hesitate to reach out to the Contensis community on Slack or raise a support ticket to get help from our team.
New support request