Class TextValidation

  • TextValidation is a DataValidation specifically for TextItems in Google Forms.

  • It can be used to set validation rules for text input, such as requiring a number within a specific range.

  • You can customize the help text shown to the user when the input is invalid.

  • TextValidation objects are created using FormApp.createTextValidation() and applied to a TextItem using setValidation().

TextValidation

A DataValidation for a TextItem .

// Add a text item to a form and require it to be a number within a range.
constform=FormApp.create('My form');
consttextItem=
form.addTextItem().setTitle('Pick a number between 1 and 100?');
consttextValidation=
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.