Template:Constraint:Format

From Wikidata
Jump to navigation Jump to search
Format: value must be formatted using this pattern (PCRE syntax).
{{{pattern}}}
Exceptions are possible as rare values may exist. Exceptions can be specified using exception to constraint (P2303).
List of violations of this constraint: Database reports/Constraint violations/Constraint:Format#Format
Documentation icon Template documentation[view · edit · history · purge ] [translate this template]

If a string also includes leading or trailing whitespaces, non printable characters, %20 marks, etc, the report will list the string as incorrectly formatted.

Constraints are described using a form of regular expression.

This template categorizes talk pages into Category:Properties with format constraints.

Usage[edit]

{{Constraint:Format|pattern=}}

Sample:

  • Two digits: {{Constraint:Format|pattern=\d\d}}
  • Two digits or more digits, the first one not being a zero {{Constraint:Format|pattern=[1-9]\d+}}

White space[edit]

Do not include spaces!

  • Good: {{Constraint:Format|pattern=\d\d}}
  • Bad: {{Constraint:Format|pattern= \d\d }}

Special formats[edit]

If the pattern includes curly braces or pipe ("|"), it needs to be included in nowiki tags.

Samples:

  • {{Constraint:Format|pattern=<nowiki>\d{1,4}</nowiki>}}
  • {{Constraint:Format|pattern=<nowiki>(tt|nm|ch|co)\d\d\d\d\d\d\d</nowiki>}}

Common values[edit]

only digits
{{Constraint:Format|pattern=<nowiki>\d+</nowiki>}}
lowercase letters, digits or a hyphen (dash)
{{Constraint:Format|pattern=<nowiki>[a-z0-9\-]+</nowiki>}}
no spaces; no slashes
{{Constraint:Format|pattern=<nowiki>[^\s\/]+</nowiki>}}

See also[edit]

External tools[edit]