【问题标题】:Does the AWS CloudFormation allowed pattern will allow # symbol in the email addressAWS CloudFormation 允许模式是否允许在电子邮件地址中使用 # 符号
【发布时间】:2016-09-04 22:48:50
【问题描述】:

我们公司的 DL 列表使用 # 符号。例如,#test-emailcheck@example.com。通过 AWS CloudFormation 模板,我们正在验证电子邮件地址。但我提到的例子不被 AWS 接受。下面是我的模板,适用于通常的电子邮件 ID,例如 test.emailcheck@example.com,

"contactemail": {
      "Description": "REQUIRED whatever dev or ops email list is appropriate for your project",
      "Type": "String",
      "AllowedPattern": "^[\\w-\\+]+(\\.[\\w]+)*@[\\w-]+(\\.[\\w]+)*(\\.[a-z]{2,})$",
      "ConstraintDescription": "must be a valid email address"
    },

我修改了允许的模式,使其与在线正则表达式https://regex101.com/r/uY6uH1/1 中的# 符号一起使用。尽管它在这里接受了。当我在 AWS CF 中尝试相同时,它不起作用。我如何在 AWS CF 模板中实现这一点。

注意:# 将来可能会更改为 $,& 任何内容。所以我不想在正则表达式中硬编码我所有的特殊字符

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    您是否确保 JSON 中的转义字符被双重转义?

    我能够使用以下模板成功验证用作contactemail 参数的电子邮件#test-emailchec@example.com

    {
      "AWSTemplateFormatVersion": "2010-09-09",
      "Resources": {
        "VPC": {
          "Type": "AWS::EC2::VPC",
          "Properties": {
            "CidrBlock": "10.0.0.0/16"
          }
        }
      },
      "Parameters": {
        "contactemail": {
          "Description": "REQUIRED whatever dev or ops email list is appropriate for your project",
          "Type": "String",
          "AllowedPattern": "^[\\x20-\\x45]?[\\w-\\+]+(\\.[\\w]+)*@[\\w-]+(\\.[\\w]+)*(\\.[a-z]{2,})$",
          "ConstraintDescription": "must be a valid email address"
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-18
      • 2011-07-14
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 2012-03-30
      • 2016-05-31
      • 2018-08-25
      • 2019-06-18
      相关资源
      最近更新 更多