A Singapore Government Agency Website

Regex patterns

A regular expression (regex) restricts the format of a form input. Use the patterns on this page in a form logic condition to check that an input is in the right format. Copy the pattern into the IF box of a logic rule. For how to add a rule, refer to Add form logic.

Condition template

Use this template in the IF field:

MATCH(@component, "regex")
Placeholder Replace with Example
@component The identifier of the component, including its position. 4TXT
"regex" The pattern, in quotation marks. "^.{3}$"

A complete example that requires exactly eight digits in the numeric component at position 5:

MATCH(5NUM, "^\d{8}$")

General patterns

Use case Pattern Example pattern Valid input Invalid input
Exactly n characters ^.{n}$ ^.{5}$ hello, 12345 hi, 123
At least n characters ^.{n,}$ ^.{3,}$ abc, 1234 hi, 1
Between n and m characters ^.{n,m}$ ^.{3,6}$ hello, abc hi, 123abc7
Letters only, any case ^[A-Za-z]+$ Not applicable OpenAI, ALLCAPS 123, 01ab
Uppercase letters only ^[A-Z]+$ Not applicable HELLO nocaps, 123
Lowercase letters only ^[a-z]+$ Not applicable hello HELLO, 123
Digits only ^\d+$ Not applicable 123456 hello, 123abc
Fixed-length digits ^\d{n}$ ^\d{7}$ 1234567 hi, 123
Letters and digits only ^[A-Za-z0-9]+$ Not applicable User123 hello!, star*
Starts with “XX” ^XX.*$ ^SG.*$ SG00123 123SG
Ends with “YY” ^.*YY$ ^.*Ltd$ OpenAI Ltd Ltd hi
Contains “ABC” ^.*ABC.*$ ^.*SG.*$ 123SG456 SinGapore
Valid email format ^[\w.-]+@[\w.-]+\.\w{2,}$ Not applicable test@example.com noemail
Allows dash or underscore ^[\w-]+$ Not applicable user_name hello!
Disallows whitespace ^[^\s]+$ Not applicable nospaces! a space

Singapore-specific patterns

Use case Pattern Valid input Invalid input
Singapore registered Unique Entity Number (UEN), before 2009 ^\d{8}[A-Z]$ 12345678B, 20031234A 123456789
Singapore registered UEN, after 2009 ^[T|S|R]\d{2}[A-Z0-9]{2}\d{4}[A-Z]$ T12LL1234A, S88FC4567F 12345678B, G12SS3456B
National Registration Identity Card (NRIC) ^[S|T|G|F]\d{7}[A-Z]$ T0012345A, S9712387B 12345678B, R1234567A
Bank code ^\d{4}$ 7171, 7339 711, abc
Bank and branch code ^\d{7}$ 7171003, 7339001 7171, abcdefg

Constraints and limitations

Constraint Detail
Component identifier Replace @component with the correct identifier of the field.
Test first Test a pattern before you use it, to confirm that it accepts and rejects the right inputs.
Supported components The match condition works with aggregate, calculated, checkbox, conditional, date, multi-selection, numeric, radio question, single selection and text components.
Chat with me!
Bot Launcher