title: Validation for URL/Domain using Regex? (Rails)
body: <p>I am trying to create a validation that checks to make sure a domain/url is valid for example "test.com"</p>
  
  <pre><code>def valid_domain_name?
    domain_name = domain.split(".")
    name = /(?:[A-Z0-9\-])+/.match(domain_name[0]).nil?
    tld = /(?:[A-Z]{2}|aero|ag|asia|at|be|biz|ca|cc|cn|com|de|edu|eu|fm|gov|gs|jobs|jp|in|info|me|mil|mobi|museum|ms|name|net|nu|nz|org|tc|tw|tv|uk|us|vg|ws)/.match(domain_name[1]).nil?
    if name == false or tld == false
      errors.add(:domain_name, 'Invalid domain name. Please only use names with letters (A-Z) and numbers (0-9).')
    end
  end
  </code></pre>
  
  <p>This is what I have so far but it doesn't work. It lets bad URLs through without failing.</p>
  
  <p>I don't know regex very well.</p>