Form Validation in Google Forms

In this previous post I talked about collecting user data using Google Drive forms.

To prevent corrupted or incorrect data being sent via these forms, it’s helpful to validate the data entered by the user to ensure that it’s correctly formatted and consistent. For example, our form must accept only a valid email address in an email entry field.

The form design tool in Google Drive lets you enter an expression that checks user data to validate it. Let’s go back to the form I made in this post, and add an extra field for the user’s telephone number:

Click image to enlarge

Click image to enlarge

I’m going to insist that this field accepts only numeric characters, in a string that must be between 5 and 15 characters in length:

Click image to enlarge

Click image to enlarge

The expression

 ^[0-9]{5-15}$

is known as a regular expression or regex; these can be a little intimidating at first, but there are plenty of tutorials on the web. (There are some more tips and examples in this post). Luckily, for many applications you won’t need to use one; the form designer has simpler options such as Contains and Does Not Contain, which are easier to use when the situation allows simpler validation. Note also that I’ve checked the box saying Required Question, to insist that the user may not leave this field empty.

Let’s see what happens when the user enters incorrect data:

Click image to enlarge

Click image to enlarge

The form issues the error message we’ve specified, and cannot be submitted until the data is corrected.

You can set up data validation for character count, numbers, postal codes, and much more.

In a later post I talk about storing and sending your forms using Gmail.