Preventing leading zeros in Google Forms using Regular Expressions

936 views
Skip to first unread message

Fazlul Haque

unread,
Mar 7, 2022, 5:55:53 AM3/7/22
to Google Apps Script Community
Hi Everyone,
I started learning App Scripts for the first time. So your help will be highly appreciated.

I created a field in Google Forms in which people will enter their (numerical) ID Numbers that will be 4 digits minimum and 11 digits maximum, and I want to prevent them to write zeros at the beginning using regular expressions.

What would the RegEx code look like?
Please help.

Regards,
Fazlul

AdamD

unread,
Mar 8, 2022, 6:38:09 AM3/8/22
to Google Apps Script Community
Hi Fazlul,

^[1-9][0-9]{3,10}$ will give you a number that does not allow a leading zero and the overall number would be 4 to 11 digits.  Also, you don't need a script for this.  You can placed this regex into the data validation area of the question on your Form.  It would be a matching pattern.

Adam

Reply all
Reply to author
Forward
0 new messages