Google Forms is an incredibly versatile tool for collecting data, ranging from customer surveys to event registrations. However, any data analyst knows the pain of “garbage in, garbage out.” If users input incorrect information—such as a phone number missing a digit or a misspelled email domain—your dataset becomes unreliable. The solution lies in Response Validation, a powerful feature that acts as a gatekeeper to ensure data accuracy before the form is even submitted.
This comprehensive guide will walk you through the nuances of Google Forms Response Validation, with a deep dive into Regular Expressions (RegEx). By mastering these techniques, you can enforce strict rules on data entry, ensuring you collect clean, usable information every time.
Understanding Response Validation Types
When you enable “Response Validation” (found by clicking the three dots at the bottom right of a question field), Google Forms offers four primary criteria to control user input. Choosing the right type is the first step toward data integrity.
- Numbers: This option is ideal for quantitative data. You can restrict inputs using mathematical logic, such as requiring a value to be “Greater than,” “Less than,” “Between” two numbers, or simply “Is number” to prevent text entry.
- Text: This is commonly used for basic content checks. You can validate if the input “Contains” or “Does not contain” specific keywords. It also includes built-in validators for “Email” and “URL,” though these basic settings often miss subtle errors.
- Length: This prevents verbosity or ensures completeness by setting a “Maximum character count” (useful for Twitter-style feedback) or a “Minimum character count” (to ensure thoughtful responses).
- Regular Expression (RegEx): This is the most advanced and flexible option. It allows you to build complex patterns that the data must match. This is the core focus of our guide, as it solves problems the other three types cannot.
The Power of Regular Expressions (RegEx)
Regular Expressions (RegEx) act as a specific language that describes a search pattern. While it may look like random code to the uninitiated, it is a standard tool in computer science for pattern matching. Below is a reference table for common RegEx characters you will use in Google Forms:
| Character/Group | Description |
|---|---|
. | Matches any single character (except newline) |
w / d / s | Word character, Digit, Whitespace |
W / D / S | NOT a word character, NOT a digit, NOT whitespace |
[abc] | Character set: matches a, b, or c |
[^abc] | Negated set: matches anything except a, b, or c |
[a-g] | Range: matches any character from a to g |
^abc$ | ^ denotes start of line; $ denotes end of line |
b / B | Word boundary, Non-word boundary |
. * \ | Escaped characters (treats special chars as literal text) |
t n r | Tab, Newline, Carriage return |
(abc) | Capturing group |
1 | Backreference to Group 1 |
(?:abc) | Non-capturing group |
(?=abc) | Positive lookahead (followed by abc) |
(?!abc) | Negative lookahead (not followed by abc) |
a* a+ a? | 0 or more, 1 or more, 0 or 1 quantifier |
a{5} | Exactly 5 occurrences |
a{2,} | 2 or more occurrences |
a{1,3} | Between 1 and 3 occurrences |
ab|cd | Alternation (ab OR cd) |
For testing your patterns before applying them, tools like Regexr are invaluable resources.
Practical Use Cases for Google Forms
While theoretical knowledge is useful, applying RegEx to real-world scenarios is where the magic happens. Here are the most common configurations you will need for the Vietnamese and global technology context.
Advanced Email Validation
Google’s default “Email” validation is good, but it is often too permissive. It might accept a typo like [email protected] or [email protected]. To ensure you are getting valid addresses—and specifically filtering out common typos or restricting specific domains—you need a custom RegEx.
Google Forms interface showing email validation settings
The following pattern is designed to catch common misspellings of “Gmail” and other providers, ensuring the user double-checks their input:
^[w-.]+@(?!.*gmai.com|mail|gmial|gmaiil|gmeo|gmaill|gnail.com|gmail.con|outlook.com.vn|mytam.info|mytamentertainment.com|yhoo.com|yaho.com|yahu.com|gmail.com.vn|gamil.com|email.com.*)([w-]+.)+[w-]{2,4}$This pattern uses a “negative lookahead” (?!...) to explicitly forbid known bad domains while accepting standard valid email formats.
Standardizing Date Formats
When you use the standard “Date” picker in Google Forms, the format depends on the user’s device settings, which can lead to mixed data (MM/DD/YYYY vs. DD/MM/YYYY). By using a “Short Answer” question with RegEx validation, you can force users to input text in a specific format like dd/mm/yyyy.
Google Forms question setup for date of birth validation
Use the code below to validate dates (handling days 01-31 and months 01-12):
(0[1-9]|[12][0-9]|3[01])[- /.]([0-9]|0[0-9]|1[012])[- /.]dddd$This ensures that the day, month, and year are entered numerically and separated by hyphens, slashes, or dots.
Post-Processing Data: A Crucial Step
Collecting data is only half the battle. Once you have validated inputs like dates or codes using RegEx in Forms, you will often need to process this data in Excel or Google Sheets. For example, you might need to convert those text-string dates into actual date objects for calculation.
Animation showing VBA macro processing data in Excel
Advanced users often utilize VBA (Visual Basic for Applications) in Excel to automate the cleanup of exported Google Forms data. RegEx can also be utilized inside these VBA scripts to further parse complex strings that were captured in the form.
Animation demonstrating data extraction in Excel
Validating Identity Documents (ID/Passport)
In Vietnam and many other countries, National ID cards (CCCD/CMND) follow a strict digit count (usually 9 or 12 digits), while passports may contain letters. The standard “Length” validator in Google Forms is insufficient because it counts spaces and special characters.
To strictly enforce format, use this RegEx pattern:
(^w{3}[0-9]{6}$)|(^w{1,2}[0-9]{7}$)|(^d{9}$)|(^d{12}$)This pattern accepts:
- Passports with 3 letters + 6 digits.
- Passports with 1-2 letters + 7 digits.
- Old ID cards (9 digits).
- New Citizen Identity Cards (12 digits).
Address and Location Validation
For address fields, you want to prevent users from entering lazy answers like “Hanoi” or “HCM.” You can enforce a minimum complexity or length to ensure a full address is provided.
Detailed Regex pattern breakdown for address validation
While address formats vary too much for a strict pattern, combining a “Minimum Character Count” with a RegEx that checks for numbers (house numbers) and text can significantly improve data quality.
Advanced: Regex in Google Sheets and Excel
Your journey with RegEx doesn’t end at the data collection stage. Google Sheets natively supports RegEx functions, allowing you to manipulate the data you have collected without complex formulas.
Key Functions:
=REGEXMATCH(text, expression): Returns TRUE if the text matches the pattern.=REGEXEXTRACT(text, expression): Extracts the substring that matches the pattern.=REGEXREPLACE(text, expression, replacement): Replaces the matching part of the text.
For instance, if you have a cell containing mixed text like “Score: 95/100”, you can easily extract just the number.
Using Regex functions to extract scores in Google Sheets
This capability is massive for data cleaning. You can separate names, phone numbers, or specific codes from a messy paragraph of text submitted via a form.
Illustration of various Regex patterns for text processing
For Excel users, RegEx functions are not built-in by default. However, you can add this functionality via VBA or by using open-source add-ins like ExcelRegex (available on GitHub). This brings the power of RegexMatch and RegexReplace to your offline spreadsheets, ensuring consistency across your entire workflow.
Conclusion
Response Validation using Regular Expressions is a game-changer for anyone relying on Google Forms for professional data collection. By moving beyond basic validation and implementing custom RegEx patterns, you ensure consistency, reduce manual data cleaning time, and eliminate common user errors.
Whether you are validating Vietnamese Citizen IDs, ensuring professional email domains, or standardizing dates, the patterns provided in this guide are your starting point. We encourage you to experiment with these expressions and integrate them into your next project to experience the efficiency of automated data control.
References
- Regex Testing Tool: regexr.com
- Excel Regex Add-in: GitHub – ExcelRegex
- VBA Regex Guide: HocExcel Online – Using RegEx in VBA










Discussion about this post