riboseinc / uri_format_validator

Validate URL for Rails
MIT License
3 stars 2 forks source link

Domain validator #94

Open skalee opened 7 years ago

skalee commented 7 years ago

A separate validator for fields storing domains may be useful. Consider following example:

class Site
  include ActiveModel::Validations

  attr_accessor :registered_domain
  validates :registered_domain, domain: { resolvable: true }
end

object = Site.new

object.registered_domain = "google.com"
object.valid? # => true

object.registered_domain = "asdfasdfasd.asdfasdfasdf.com"
object.valid? # => false

This is just an early concept. I'm not yet sure what validation options will be useful. I guess checking that domain is resolvable, and that host is reachable. Also some checks like if it fits given regexp, or is subdomain of given domain, things like that..

ronaldtse commented 6 years ago

LGTM!