Loading...
 
Skip to main content

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:

  1. Only records with more than 2 letters in the field are allowed:
    Copy to clipboard
    ^.{3,}$

  2. Only lowercase letters, numbers and dashes are allowed:
    Copy to clipboard
    ^[a-z0-9\-]+$

  3. Only lowercase letters in emails, therefore, letters, numbers, dots, dashes and underscores are allowed:
    Copy to clipboard
    ^[a-z0-9.\@\-\_]+$

    Or an alternative (and more permissive) approach: all except uppercase letters:
    Copy to clipboard
    ^[^A-Z]+$

  4. Numbers between 0 and 1 (very useful to validate probabilities):
    Copy to clipboard
    ^((0(\.[0-9]*)?)|(1(\.0)?))$

  5. Numbers between 0 and 100 (useful for positive values under and 3 digit threshold like 100):
    Copy to clipboard
    ^[0-9]{1}$|^[0-9]{1}[0-9]{1}$|^[1]{1}[0]{1}[0]{1}$|^100$

  6. Positive numbers or zero only (useful for measurements of concentrations of chemical substances, for instance):
    In Tiki 12.x LTS
    Copy to clipboard
    ^[0]{1}$|^(?!0*[.,]0*$|[.,]0*$|0*$)\\d+[,.]?\\d{0,2}$


    Since Tiki 14.x
    Copy to clipboard
    ^[0]{1}$|^(?!0*[.,]0*$|[.,]0*$|0*$)\d+[,.]?\d{0,2}$

  7. Uppercase letter, two numbers, dash, two numbers (e.g.: X00-00)
    Copy to clipboard
    [A-Z][0-9][0-9]-[0-9][0-9]

  8. Any user with the domain name ending with .example.com
    Copy to clipboard
    /(^[^@]*@[^,]*.example.com$)/

Alias names for this page

Regexp | Regular Expression | Regular Expressions | RegularExpression | RegularExpressions | regex