Class TextValidation
Stay organized with collections
Save and categorize content based on your preferences.
TextValidation
A DataValidation for a TextItem
.
// Add a text item to a form and require it to be a number within a range.
const form = FormApp.create('My form');
const textItem =
form.addTextItem().setTitle('Pick a number between 1 and 100?');
const textValidation =
FormApp.createTextValidation()
.setHelpText('Input was not a number between 1 and 100.')
.requireNumberBetween(1, 100)
.build();
textItem.setValidation(textValidation);
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.
[null,null,["Last updated 2024-12-02 UTC."],[[["\u003cp\u003e\u003ccode\u003eTextValidation\u003c/code\u003e is used to apply specific data validation rules to text-based form responses collected through a \u003ccode\u003eTextItem\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt enables defining criteria like number ranges, custom error messages (using \u003ccode\u003esetHelpText\u003c/code\u003e), and applying these constraints via \u003ccode\u003esetValidation\u003c/code\u003e on the target \u003ccode\u003eTextItem\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe example demonstrates setting a numeric constraint, requiring user input to fall between 1 and 100 with a clear error message if the input is invalid.\u003c/p\u003e\n"]]],[],null,["# Class TextValidation\n\nTextValidation\n\nA DataValidation for a [TextItem](/apps-script/reference/forms/text-item).\n\n```javascript\n// Add a text item to a form and require it to be a number within a range.\nconst form = FormApp.create('My form');\nconst textItem =\n form.addTextItem().setTitle('Pick a number between 1 and 100?');\nconst textValidation =\n FormApp.createTextValidation()\n .setHelpText('Input was not a number between 1 and 100.')\n .requireNumberBetween(1, 100)\n .build();\ntextItem.setValidation(textValidation);\n```"]]