How to specify and validate input formats in Google Forms

Google Forms are very useful when conducting surveys, accepting applications, and so on.

However, have you ever had trouble dealing with the various formats of responses submitted?

Employee IDNamePhone numberZip code
A00111Hugo First123-456-789012345-1234
b00222A. Mused0987654321987654321
c-333Constance Noring(111) 222-333311111-2222
D-00444Lois Di Nominator222-333-4444333334444

I don’t want to see a lack of uniformity in format when tabulating surveys and post-application work. I think it makes the work super inefficient.

Although it is possible to format the data to some extent by using Google Spreadsheet or Excel functions, if at all possible, we would like the submission to be formatted at the time it is received.

Therefore, in this article, I would like to explain How to restrict the input format or limit the number of input characters in Google Forms, including how to use regular expressions, in addition to basic techniques.

Basics: Description and Example

First, as basic as it may sound, provide a clear explanation of what respondents should enter, and include an example.

You can post this information by pressing Description from the menu at the bottom right of the card.

selected "Description" from the menu on the bottom right of the card in question.

For example, if you are asking for a hyphen-delimited phone number, I think it would be better to describe it as follows.

The following text was entered in the Question Description field. Enter your phone number in the following format: Example: (555) 555-1234

I have never lived in the US and am not very familiar with US customs… Sorry if my sample is not appropriate.

This is basic, but very important for collecting well-organized data.

Use standard validation

Google Forms makes it easy to validate and restrict input formats, even for those who are not knowledgeable about them.

You can set up an input validation by pressing Response validation from the menu at the bottom right of the card.

selected "Response validation" from the menu on the bottom right of the card in question.

With this function, you can, for example, set a maximum number of entries, allow only text containing a given string of characters, allow only email address formatting, etc… and so on, with various validation and entry restrictions.

You can also set up error messages when incorrectly formatted responses are entered.

For example, to allow only the email address format to be entered, configure as shown in the image below.

For the question titled "Email", the validation of the input value was set as follows. From the left field, "Text", "Email", and "invalid Email Format".

If a respondent enters an incorrect value, a warning will be displayed as shown in the image below.

When an invalid answer was entered in the "Email" answer field on the preview screen, the error message "invalid Email Format" was displayed.

If such an incorrect value is entered, the response will not be submitted even if the Submit button is pressed.

As of this writing (December 13, 2022), the following validations can be set.

Rule TypeRule
NumberGreater than Number
Greater than or equal to Number
Less than Number
Less than or equal to Number
Equal to Number
Not equal to Number
Between Number1 and Number2
Not between Number1 and Number2
is number
Whole number
TextContains Text
Doesn’t contain Text
Email
URL
LengthMaximum character count
Minimum character count
Regular expression* I will explain in the next chapter.

Set custom input restrictions using regular expressions

I explained how to set up general input restrictions, but that is not enough to handle zip codes, phone numbers, and other unique things like your company’s employee number, your customer’s membership number … and so on.

Using regular expressions, those input values can also be validated.

A regular expression (shortened as regex or regexp; sometimes referred to as rational expression) is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for “find” or “find and replace” operations on strings, or for input validation.

https://en.wikipedia.org/wiki/Regular_expression

For now, let’s put it into practice with Phone Number.

Select “Regular expression” and “Matches” and enter \([0-9]{3}\) [0-9]{3}-[0-9]{4} for the pattern.

Also specify Custom error text if necessary.

For the question titled "Phone Number", the validation of the input value was set as follows. In order from the left input field, "Regular exporession", "Matches", "\([0-9]{3}\) [0-9]{3}-[0-9]{4}", "Please enter the correct format.

This pattern means a string of “three digits surrounded by parentheses, a space, three digits, a hyphen, and four digits”.

Incidentally, the second drop-down can be selected from the following four types.

ContainsAllow strings containing the specified pattern
Doesn’t containAllow strings that do not contain the specified pattern
MatchesAllow strings that exactly match the specified pattern
Doesn’t matchAllow strings that do not exactly match the specified pattern

Regular expressions are deep and can be difficult to understand.
You can read Google’s help or do a Google search like “phone number regex“.

Notes on setting validation

I hope you have found that you can put quite a variety of input restrictions on Google Forms.

If you have a solid input form validation setup, it should help you because it will accumulate data that is easy to utilize.
On the other hand, however, it is important to note that respondents will not be able to submit exceptional responses.

For example, restricting the phone number as in the previous example may make it impossible for people living in other countries to submit the form.
Also, symbols such as hyphens, parentheses, and spaces may be difficult for some respondents to enter correctly.

While setting input format validation makes the survey administrator’s tabulation work more convenient, it can also be inconvenient for respondents, so it is important to carefully consider how strictly validation should be set.

In addition, note that the various numbering and code schemes are subject to change for any reasons.

Comments

Copied title and URL