Loading...
 
Skip to main content

History: Regexps

Source of version: 15 (current)

Copy to clipboard
            ! Regular Expressions
Examples of regular expressions to be used in some parts of Tiki

Tracker validation fields, such as text fields, allow to have some check against a regular expression. Some examples are:

# Only records with more than 2 letters in the field are allowed:
+ {CODE(colors="perl")}
^.{3,}$
{CODE}
+ ~tc~^~/tc~
# Only lowercase letters, numbers and dashes are allowed:
+ {CODE(colors="perl")}
^[a-z0-9\-]+$
{CODE}
+ ~tc~^~/tc~
# Only lowercase letters in emails, therefore, letters, numbers, dots, dashes and underscores are allowed:
+ {CODE(colors="perl")}
^[a-z0-9.\@\-\_]+$
{CODE}
+ ~tc~^~/tc~ Or an alternative (and more permissive) approach: all except uppercase letters:
+ {CODE(colors="perl")}
^[^A-Z]+$
{CODE}
+ ~tc~ ~/tc~
# Numbers between 0 and 1 (very useful to validate probabilities):
+ {CODE(colors="perl")}
^((0(\.[0-9]*)?)|(1(\.0)?))$
{CODE}
+ ~tc~^~/tc~
# Numbers between 0 and 100 (useful for positive values under and 3 digit threshold like 100):
+ {CODE(colors="perl")}
^[0-9]{1}$|^[0-9]{1}[0-9]{1}$|^[1]{1}[0]{1}[0]{1}$|^100$
{CODE}
+ ~tc~^~/tc~
# Positive numbers or zero only (useful for measurements of concentrations of chemical substances, for instance):
+ {CODE(colors="perl", caption="In Tiki 12.x LTS")}
^[0]{1}$|^(?!0*[.,]0*$|[.,]0*$|0*$)\\d+[,.]?\\d{0,2}$
{CODE}
+ ~tc~^~/tc~
+ {CODE(colors="perl", caption="Since Tiki 14.x")}
^[0]{1}$|^(?!0*[.,]0*$|[.,]0*$|0*$)\d+[,.]?\d{0,2}$
{CODE}
+ ~tc~^~/tc~
# Uppercase letter, two numbers, dash, two numbers (e.g.: X00-00)
+ {CODE(colors="perl")}
[A-Z][0-9][0-9]-[0-9][0-9]
{CODE}
+ ~tc~^~/tc~
# Any user with the domain name ending with .example.com
+ {CODE(colors="perl")}
/(^[^@]*@[^,]*.example.com$)/
{CODE}

-= Alias names for this page =-
(alias(Regexp)) | (alias(Regular Expression)) | (alias(Regular Expressions)) | (alias(RegularExpression)) | (alias(RegularExpressions)) | (alias(regex))