我正在尝试通过cloudformation创建一个s3存储桶。我尝试使用正则表达式^([0-9a-z .-]){3,63} $,但它也接受根据新的s3命名约定无效的模式“ ...”和“ ---”。(请参阅:https : //docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html)请帮忙?
如何正确验证子域格式?
这是我所拥有的:
validates :subdomain, uniqueness: true, case_sensitive: false
validates :subdomain, format: { with: /\A[A-Za-z0-9-]+\z/, message: "not a valid subdomain" }
validates :subdomain, exclusion: { in: %w(support blog billing help api www host admin en ru pl ua us), message: "%{value} is reserved." }
validates :subdomain, length: { maximum: 20 }
before_validation :downcase_subdomain
protected
def downcase_subdomain
self.subdomain.downcase! if attribute_present?("subdomain")
end
Run Code Online (Sandbox Code Playgroud)
题:
是否有像电子邮件一样的标准 REGEX 子域验证?子域使用的最佳正则表达式是什么?
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, allow_blank: true