Class TextValidationBuilder Stay organized with collections Save and categorize content based on your preferences.
Page Summary
TextValidationBuilder is a DataValidationBuilder used for creating text validation rules in forms.
It provides methods to require text items to be numbers, within specific ranges, or matching/not matching patterns.
You can also require text items to be email addresses, URLs, or have a specific length.
The builder allows chaining methods to apply multiple validation rules.
A DataValidationBuilder for aText.
// 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);
Methods
| Method | Return type | Brief description |
|---|---|---|
require | Text | Requires text item to be a number. |
require | Text | Requires text item to be a number between start and end, inclusive. |
require | Text | Requires text item to be a number equal to value specified. |
require | Text | Requires text item to be a number greater than the value specified. |
require | Text | Requires text item to be a number greater than or equal to the value specified. |
require | Text | Requires text item to be a number less than the value specified. |
require | Text | Requires text item to be a number less than or equal to the value specified. |
require | Text | Requires text item to be a number not between start and end, inclusive. |
require | Text | Requires text item to be a number not equal to the value specified. |
require | Text | Requires response to contain pattern. |
require | Text | Requires response to not contain pattern. |
require | Text | Requires response to not match pattern. |
require | Text | Requires text item to be an email address. |
require | Text | Requires text item to be a URL. |
require | Text | Requires response length to be greater than or equal to value. |
require | Text | Requires response length to be less than value. |
require | Text | Requires response to match pattern. |
require | Text | Requires text item to be a whole number. |
Detailed documentation
requireNumber()
requireNumberBetween(start, end)
Requires text item to be a number between start and end, inclusive.
Parameters
| Name | Type | Description |
|---|---|---|
start | Number | the lower bounds of the inclusive range |
end | Number | the upper bounds of the inclusive range |
Return
Text — thisText, for chaining
requireNumberEqualTo(number)
Requires text item to be a number equal to value specified.
Parameters
| Name | Type | Description |
|---|---|---|
number | Number | the value which the item must be equal to. |
Return
Text — thisText, for chaining
requireNumberGreaterThan(number)
Requires text item to be a number greater than the value specified.
Parameters
| Name | Type | Description |
|---|---|---|
number | Number | the value which the item must be greater than. |
Return
Text — thisText, for chaining
requireNumberGreaterThanOrEqualTo(number)
Requires text item to be a number greater than or equal to the value specified.
Parameters
| Name | Type | Description |
|---|---|---|
number | Number | the value which the item must be greater than or equal to. |
Return
Text — thisText, for chaining
requireNumberLessThan(number)
Requires text item to be a number less than the value specified.
Parameters
| Name | Type | Description |
|---|---|---|
number | Number | the value which the item must be greater than. |
Return
Text — thisText, for chaining
requireNumberLessThanOrEqualTo(number)
Requires text item to be a number less than or equal to the value specified.
Parameters
| Name | Type | Description |
|---|---|---|
number | Number | the value which the item must be less than or equal to. |
Return
Text — thisText, for chaining
requireNumberNotBetween(start, end)
Requires text item to be a number not between start and end, inclusive.
Parameters
| Name | Type | Description |
|---|---|---|
start | Number | the lower bounds of the inclusive range |
end | Number | the upper bounds of the inclusive range |
Return
Text — thisText, for chaining
requireNumberNotEqualTo(number)
Requires text item to be a number not equal to the value specified.
Parameters
| Name | Type | Description |
|---|---|---|
number | Number | the value which the item must not be equal to. |
Return
Text — thisText, for chaining
requireTextContainsPattern(pattern)
Requires response to contain pattern.
Parameters
| Name | Type | Description |
|---|---|---|
pattern | String | text must contain pattern |
Return
Text — this for chaining
requireTextDoesNotContainPattern(pattern)
Requires response to not contain pattern.
Parameters
| Name | Type | Description |
|---|---|---|
pattern | String | text must not contain pattern |
Return
Text — this for chaining
requireTextDoesNotMatchPattern(pattern)
Requires response to not match pattern.
Parameters
| Name | Type | Description |
|---|---|---|
pattern | String | text must not match pattern |
Return
Text — this for chaining
requireTextIsEmail()
Requires text item to be an email address.
Return
Text — thisText, for chaining
requireTextIsUrl()
requireTextLengthGreaterThanOrEqualTo(number)
Requires response length to be greater than or equal to value.
Parameters
| Name | Type | Description |
|---|---|---|
number | Integer | paragraph text length must be greater than this value |
Return
Text — this for chaining
requireTextLengthLessThanOrEqualTo(number)
Requires response length to be less than value.
Parameters
| Name | Type | Description |
|---|---|---|
number | Integer | paragraph text length must be less than or equal to this value |
Return
Text — this for chaining
requireTextMatchesPattern(pattern)
Requires response to match pattern.
Parameters
| Name | Type | Description |
|---|---|---|
pattern | String | text must match pattern |
Return
Text — this for chaining
requireWholeNumber()
Requires text item to be a whole number.
Return
Text — thisText, for chaining
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.