Regular Expressions

You can set custom regular expressions for fill-in-the-blank questions to strictly control valid answer formats. Replace [q*] with your specific question number in the examples below:

Regular Expressions

Note: Replace [q*] with your actual question number in the regex pattern.

regular expressions

1. Email Address Validation

Regular Expression:
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
Description: Matches standard email format (e.g., [email protected]).
Examples:
Valid: [email protected]
Invalid: [email protected]

2. ZIP Code Validation

Regular Expression:
/^\d{5}(-\d{4})?$/
Description: Matches 5-digit basic ZIP codes (e.g., 12345) or 9-digit extended ZIP codes (e.g., 12345-6789).
Examples:
Valid: 90210 or 10001-2345
Invalid: 1234 (less than 5 digits)

3. Social Security Number (SSN) Validation

Regular Expression:
/^\d{3}-\d{2}-\d{4}$/
Description: Matches SSN in XXX-XX-XXXX format (e.g., 123-45-6789).
Examples:
Valid: 555-12-3456
Invalid: 123456789 (missing separators)

4. Date Format Validation (MM/DD/YYYY)

Regular Expression:
/^(0[1-9]|1[0-2])[-.\/](0[1-9]|[12][0-9]|3[01])[-.\/]([0-9]{4})$/
Description: Matches dates in MM/DD/YYYY format (e.g., 02/29/2020).
Examples:
Valid: 12-31-2023、12.31.2023、12/31/2023
Invalid: 13/01/2024 (invalid month)

FAQ

Q1: What is the Regular Expression function? What does it do?

A: The Regular Expression function allows setting custom regular expressions for fill-in-the-blank questions, strictly controlling valid answer formats. This ensures data accuracy and consistency, preventing invalid data input.


Q2: How to use regular expressions to validate email addresses?

A: Use the regular expression: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/. This expression matches standard email format, for example: [email protected] is valid, while [email protected] is invalid.


Q3: How to validate ZIP code format?

A: Use the regular expression: /^\d{5}(-\d{4})?$/. This expression matches 5-digit basic ZIP codes (such as 12345) or 9-digit extended ZIP codes (such as 12345-6789). Numbers with fewer than 5 digits (such as 1234) are invalid.


Q4: How to validate Social Security Number format?

A: Use the regular expression: /^\d{3}-\d{2}-\d{4}$/. This expression matches SSN in XXX-XX-XXXX format, for example: 555-12-3456 is valid, while 123456789 without separators is invalid.


Q5: How to validate date format?

A: Use the regular expression: /^(0[1-9]|1[0-2])[-.\/](0[1-9]|[12][0-9]|3[01])[-.\/]([0-9]{4})$/. This expression matches dates in MM/DD/YYYY format, supporting multiple separators (such as 12-31-2023, 12.31.2023, 12/31/2023), but invalid months (such as 13/01/2024) will be rejected.


How helpful was this article?