title: Validate format of subdomain
body: <p>How can I properly validate a subdomain format?</p>
  
  <p>Here's what I've got:</p>
  
  <pre><code>  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  
  </code></pre>
  
  <p>Question: </p>
  
  <p>Is there a standard REGEX subdomain validation like there is for email? What is the best REGEX for subdomain to use?</p>
  
  <p><code>validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, allow_blank: true</code></p>