Class Validation
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
验证
一个对象,用于为其附加的微件定义验证规则。
适用于 Google Chat 应用和 Google Workspace 插件。
const validation = CardService.newValidation().setCharacterLimit('10').setInputType(
CardService.InputType.TEXT);
详细文档
setCharacterLimit(characterLimit)
设置 widget 的字符数限制。
适用于 Google Chat 应用和 Google Workspace 插件。
参数
名称 | 类型 | 说明 |
characterLimit | Integer | 要设置的字符数限制。请注意,此限制仅适用于 TextInput ,其他微件会忽略此限制。 |
返回
Validation
- 此对象,用于链式调用。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eValidation objects define rules for widgets, such as character limits and input types, ensuring data integrity.\u003c/p\u003e\n"],["\u003cp\u003eThey are available for Google Chat apps and Workspace Add-ons, offering developers control over user input.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can leverage methods like \u003ccode\u003esetCharacterLimit\u003c/code\u003e and \u003ccode\u003esetInputType\u003c/code\u003e to customize validation behavior.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003esetCharacterLimit\u003c/code\u003e method specifically applies to \u003ccode\u003eTextInput\u003c/code\u003e widgets, enforcing maximum character input.\u003c/p\u003e\n"],["\u003cp\u003eSimilarly, \u003ccode\u003esetInputType\u003c/code\u003e dictates the accepted input type, enhancing user experience and data accuracy.\u003c/p\u003e\n"]]],[],null,["# Class Validation\n\nValidation\n\nAn object that defines the validation rule for the widget that it is attached to.\n\nAvailable for Google Chat apps and Google Workspace add-ons.\n\n```javascript\nconst validation = CardService.newValidation().setCharacterLimit('10').setInputType(\n CardService.InputType.TEXT);\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|------------------------------------------------------------------|-----------------|-----------------------------------------|\n| [setCharacterLimit(characterLimit)](#setCharacterLimit(Integer)) | [Validation](#) | Sets the character limit of the widget. |\n| [setInputType(inputType)](#setInputType(InputType)) | [Validation](#) | Sets the input type of the widget. |\n\nDetailed documentation\n----------------------\n\n### `set``Character``Limit(characterLimit)`\n\nSets the character limit of the widget.\n\nAvailable for Google Chat apps and Google Workspace add-ons.\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------------|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `character``Limit` | `Integer` | The character limit to set. Note that this restriction is only effective for [TextInput](/apps-script/reference/card-service/text-input) and is ignored for other widgets. |\n\n#### Return\n\n\n[Validation](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Input``Type(inputType)`\n\nSets the input type of the widget.\n\nAvailable for Google Chat apps and Google Workspace add-ons.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------------|-------------------------------------------------------------|-------------------------------------------------------------------------|\n| `input``Type` | [InputType](/apps-script/reference/card-service/input-type) | The [InputType](/apps-script/reference/card-service/input-type) to set. |\n\n#### Return\n\n\n[Validation](#) --- This object, for chaining."]]