【问题标题】:Validating response text in a Google Form with Regex in Google App Script使用 Google App 脚本中的正则表达式验证 Google 表单中的响应文本
【发布时间】:2018-04-19 15:51:14
【问题描述】:

我想使用正则表达式验证响应文本,我知道它可以手动完成 (https://www.labnol.org/internet/regular-expressions-forms/28380/)。

但是,当我们使用 Google App Script 构建表单时,我正在尝试使用 FormApp.createTextValidation() 来构建所需的验证。有许多不同的方法可用 (https://developers.google.com/apps-script/reference/spreadsheet/data-validation-builder),但它们似乎都是预先设置好的。由于我们可能有非常具体的验证格式,我们需要编写自己的正则表达式来验证响应。这可能吗?

提前非常感谢!

【问题讨论】:

    标签: regex google-apps-script google-forms


    【解决方案1】:

    第二个链接适用于电子表格,而不适用于表单。而不是那个链接,你必须查看Class TextValidationBuilder,更具体地说

    • requireTextContainsPattern(模式)
    • requireTextDoesNotContainPattern(pattern)
    • requireTextDoesNotMatchPattern(模式)

    【讨论】:

    • 这是完美的答案!我最初认为模式必须完全匹配,但结果是接受正则表达式!非常感谢!
    猜你喜欢
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-30
    • 1970-01-01
    相关资源
    最近更新 更多