Skip to content
Question Regular Expressions

Question Regular Expressions

A single reference page for common regex patterns you can reuse across question fields (like catalog item variables).

Note: A helpful resource for testing and building regex patterns is regex101.com. It provides real-time feedback and explanations for your regex.

How Question Regular Expressions Work

  1. Create a record in Service Catalog > Catalog Variables > Variable Validation Regex with the regex and validation message.
  2. Reference that regex record on a question field (for example, a catalog item variable).
  3. User input is validated in real time and on submit using the provided message.

Email Address Validation

Validates a single email address with common username and domain rules.

Regex

EmailAddress.regex
1
^(?![\.])[a-zA-Z0-9!#$%*\/?|^{}\`~&'\+\-=_.]+(?<![.]+)@(?![\.-])[a-zA-Z0-9-_\.]+(\.[a-zA-Z0-9_]+)$

Explanation Validates a single email by checking a safe local part, one @, and a dot-separated domain.

Validation Message Not a valid email

IPv4 Address Validation

Accepts valid IPv4 addresses only.

Regex

IPv4Address.regex
1
^\s*(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\s*$

Explanation Matches four dot-separated octets, each constrained to 0-255.

Validation Message Not a valid IPv4 address

IPv6 Address Validation

Accepts valid IPv6 addresses only.

Regex

IPv6Address.regex
1
^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$

Explanation Matches standard IPv6 forms with optional compressed groups and embedded IPv4 where allowed.

Validation Message Not a valid IPv6 address

Network Share Name Validation

Allows letters, numbers, underscores, and hyphens with no spaces.

Network share names often include spaces or special characters that break scripts and automation. Apply this regex to allow only safe characters for share names and follow a consistent naming convention.

Regex

NetworkShareName.regex
1
^[A-Za-z0-9_-]{1,80}$

Explanation Restricts to 1-80 characters and allows only letters, numbers, underscores, and hyphens.

Validation Message Must be 1-80 chars (A-Z, 0-9, _, -), no spaces or special characters

Phone Number Validation (US)

Validates 10-digit US phone numbers with optional country code and common separators.

Regex

PhoneNumber.regex
1
^(\+\d{1,2}\s?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$

Explanation Allows optional country code, optional parentheses, and common separators for a 10-digit US number.

Validation Message Please enter a valid phone number

Phone Number Validation (International)

Validates international phone numbers with a required plus sign and country code.

Regex

InternationalPhoneNumber.regex
1
^\+(?=(?:\D*\d){7,15}\D*$)[1-9][\d\s().-]*$

Explanation Requires a leading plus sign and country code, allows common separators, and limits the number to 7-15 digits.

Validation Message Enter number with + and country code, e.g. +1 555 123 4567

Server Name Validation

Enforces server naming with only letters, numbers, and hyphens. No leading or trailing hyphens.

Server names often drift from naming standards and introduce invalid characters or whitespace. Apply this question regex to standardize server names across catalog items and forms.

Regex

ServerName.regex
1
^(?!-)[A-Za-z0-9-]{3,}(?<!-)$

Explanation Requires at least 3 characters, allows letters/numbers/hyphens, and blocks leading or trailing hyphens.

Validation Message Must be 3-15 chars (A-Z, 0-9, -), no leading/trailing hyphens or spaces

Note This pattern enforces a minimum of 3 characters with no maximum. Change {3,} to {3,15} if you want a 15-character max. In my case the variable hasa “max_length=15” variable attribute that handles the max length, so I only enforce the minimum in the regex. Adjust as needed for your use case.

URL Validation

Matches URLs with http, https, ftp, or a leading www.

Regex

URL.regex
1
(((ftp|http|https):\/\/)|(www\.))([-\w\.\/#$\?=+@&%_:;]+)

Explanation Accepts URLs starting with a scheme or www, then matches common URL-safe characters.

Validation Message Not a valid URL

US Zip Code Validation

Accepts 5-digit ZIP codes and ZIP+4.

Regex

USZipCode.regex
1
^[0-9]{5}(?:-[0-9]{4})?$

Explanation Matches a 5-digit ZIP with an optional 4-digit extension.

Validation Message Incorrect zip code

Last updated on