1

I'm using a free text field in a Google Form. Users should be able to enter the name of a product followed by its price, then start a next line for the next product. To validate their entry I want to use regular expressions.

Example entries:

Coke .25 2.50
Beer 0,33 3.30 
Chai Latte Soy 4.50 
... and so on

These are the exact requirements for what a user can enter:

  • a string containing digits, letters, and other punctuation such as commas, spaces, periods, dashes etc. This string should be no longer than 20 characters tops.
  • a space (to separate the name of the product from its price)
  • a price value, min. "0.0" and max. "9999.99". It is important that the decimal is separated by a "." and not a ","
  • a line break after each product

This is what I have:

((\w|\s|\S){1,20}\s\d{1,4}\.\d{1,2}\s){1,50}

It works OK for the first two lines, but when I try to enter a third line the script breaks. My browser asks me to stop or debug the script.

What is wrong with the regular expression? Any pointers are appreciated!

  • When I tried a variant of your regex my browser just freezes. Please, on the Google Form editor, use the ? > Report a problem to let Google engineers about the bug, I will do the same. – Rubén Oct 26 '16 at 13:25
1

Short answer

Looks that you found a failure on the user Google Forms user input sanitation. Please, on the Google Form editor, use the ? > Report a problem to let Google Form team engineers know about problem.

Explanation

A regular expression used as data validation rule should not make the browser through an error message. If the data validation is invalid, the Google Form should display an error message to the form editor.

Regarding the bonus question, that is the way that data validation work on Google Forms. You could also send feedback to Google about this too.

Related posts

Google Docs Help Forum

Google forms keeps failing to save when certain regular expressions are entered., posted on September 15, 2016

| improve this answer | |
1

If you use a regular expression with improper syntax (according to Google's regex rules found here), it will crash the browser when it tries to autosave.

For example, in PHP and Java you can use curly brackets as literals. However, Google uses the curly bracket as a quantifier. If you use the curly bracket as a literal (i.e. without escaping it) in a Google form, it will crash.

As a rule of thumb, try escaping all special characters, even if they are contained within a set (i.e. within square brackets).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.