JetBrains Space Help

Regular Expressions in Custom Fields

Custom fields can be added to some team directory forms (profile, absence, team membership) and project issues to collect and display additional information.

If you want to add a custom field with a restricted input, you can use regular expressions to create an input mask that will prevent invalid entries and help people enter data into the field in the correct predefined format.

Regular expression (regex or regexp) is a pattern describing which characters can be entered into the field and the order in which they must appear. For example, you can use a regular expression to make sure that people enter correctly formatted phone numbers into a phone number field.

Regular expression syntax

A regex uses special characters to create a pattern. To write an expression, use common regex examples and the syntax cheat-sheet below: For a comprehensive regex tutorial, you can refer to regular-expressions.info or other online resources of your choice.

Character classes
.Any character except newline
[abc]Any of a, b, or c
[b-f]Character between b and f
\w \d \sWord, digit, whitespace
\W \D \SNot word, digit, whitespace
Quantifiers and Alternation
ab|cdMatch ab or cd
a{3} a{2,}Exactly three; two or more
a* a+ a?0 or more, 1 or more, 0 or 1
a{2,5}Between two and five
a+? a{2,}?Match as few as possible
Anchors
^abc$Start / end of the string
\bWord boundary
Escape characters
\. \* \\

\ is used to escape special characters.

\* matches *

\t \n \rTab, linefeed, carriage return

Common regex use cases

Email
/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})*$/
Common email address
URL
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#()?&//=]*)/
Must include http(s)
/(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/
http(s) is optional
Phone numbers
/^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$/
Country code/extension is optional
Goverment-issued IDs
/^((?!219-09-9999|078-05-1120)(?!666|000|9\d{2})\d{3}-(?!00)\d{2}-(?!0{4})\d{4})|((?!219 09 9999|078 05 1120)(?!666|000|9\d{2})\d{3} (?!00)\d{2} (?!0{4})\d{4})|((?!219099999|078051120)(?!666|000|9\d{2})\d{3}(?!00)\d{2}(?!0{4})\d{4})$/
Social security number
/^[A-PR-WY][1-9]\d\s?\d{4}[1-9]$/
Passport number
Digits
/^\d+$/
Whole numbers
/^\d*\.\d+$/
Decimal numbers
/^\d*(\.\d+)?$/
Whole and decimal numbers
Alphanumeric characters
/^[a-zA-Z0-9]*$/
Alphanumeric characters without space
/^[a-zA-Z0-9 ]*$/
Alphanumeric characters with space
Date
/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/
Date format YYYY-MM-dd using separator -
/^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/
Date format dd-MM-YYYY using separators - or . or /
/^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]|(?:Jan|Mar|May|Jul|Aug|Oct|Dec)))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2]|(?:Jan|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec))\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)(?:0?2|(?:Feb))\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9]|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep))|(?:1[0-2]|(?:Oct|Nov|Dec)))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/
Date format dd-mmm-YYYY using separators - or . or /
Time
/^(0?[1-9]|1[0-2]):[0-5][0-9]$/
12-hour format HH:MM. Leading 0 is optional.
/((1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm]))/
12-hour format HH:MM. Leading 0 is optional. Meridiems AM/ PM are required.
/^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/
24-hour format HH:MM. Leading 0 is required.
/^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/
24-hour format HH:MM. Leading 0 is optional.
/(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)/
24-hour format HH:MM:SS
Last modified: 20 April 2021