Docxpresso comes equipped with the following standard validations:
- Date (the default date format may be set by the platform administrator in a global fashion)
That covers the simplest cases but certainly not all possible scenarios.
One may define custom validations that extend the predefined ones in ways that may be particularly useful for certain templates.
In order to do so you should first click on Resources > Create validation and provide the following data:
- Name: that uniquely defines the current custom validation.
- Type:that can be date or regular expression.
- Expression: the actual validation (more on this below).
- Description: a brief description of the custom validation that may further help to identify potential usages.
Date type validations
The date format, may be a combination of d, dd, D, DD, m, mm, M, MM, yy, yyyy, e.g. dd/mm/yyyy or DD MM dd, yyyy
- d, dd: Numeric date, no leading zero and leading zero, respectively, e.g. 2, 02.
- D, DD: Abbreviated and full weekday names, respectively, e.g. Mon, Monday.
- m, mm: Numeric month, no leading zero and leading zero, respectively, e.g. 4, 04.
- M, MM: Abbreviated and full month names, respectively, e.g. Jan, January.
- yy, yyyy: 2- and 4-digit years, respectively, e.g. 15, 2015.
If you want to use the reserved chars: D, M, Y, d, m and y as plain text you should include instead their corresponding HTML entities, namely: D, M, Y, d, m and y respectively.
Regular Expression type validations
In order to create a custom validation based on regular expressions you must be familiar with the standard.
It is out of the scope of this tutorial to explain how regular expressions work but there are excellent online tutorials that may be found on the Internet as well as online tools to test them: https://regex101.com/ that also include regex libraries with regular expressions for almost any use case that may be used out of the box.
Using custom validations
In order to apply a particular validation to a field in your template you just have to choose it from the format dropdown menu in the variable editing interface: