Skip to content
Snippets Groups Projects
README.rdoc 4.40 KiB

ValidatesHostname

Description

Extension to ActiveRecord::Base for validating hostnames and domain names.

Features

  • Adds validation for hostnames to ActiveModel

  • Supports I18n for the error messages

Installation

As plugin (from master)

rails plugin install git://github.com/KimNorgaard/validates_hostname.git

As gem

# in Gemfile
gem 'validates_hostname', '~> 1.0'

# Run bundler
$ bundle install

Validations performed

  • maximum length of hostname is 255 characters

  • maximum length of each hostname label is 63 characters

  • characters allowed in hostname labels are a-z, A-Z, 0-9 and hyphen

  • labels do not begin or end with a hyphen

  • labels do not consist of numeric values only

Options

  • option to allow for underscores in hostname labels

  • option to require that the last label is a valid TLD (ie. require that the name is a FQDN)

  • option to allow numeric values in the first label of the hostname (exception: the hostname cannot consist of a single numeric label)

  • option to specify a list of valid TLDs

  • options to allow for wildcard hostname in first label (for use with DNS)

See also www.zytrax.com/books/dns/apa/names.html

How to use

Simple usage

class Record < ActiveRecord::Base
  validates :name, :hostname => true
end

With options