https://github.com/shuber/validates_as_hostname_label
Checks for valid hostname labels (i.e. subdomains)
https://github.com/shuber/validates_as_hostname_label
Last synced: about 1 year ago
JSON representation
Checks for valid hostname labels (i.e. subdomains)
- Host: GitHub
- URL: https://github.com/shuber/validates_as_hostname_label
- Owner: shuber
- License: mit
- Created: 2009-01-14T04:40:50.000Z (over 17 years ago)
- Default Branch: master
- Last Pushed: 2023-01-19T03:08:10.000Z (over 3 years ago)
- Last Synced: 2025-04-17T14:43:43.148Z (about 1 year ago)
- Language: Ruby
- Homepage: http://rdoc.info/projects/shuber/validates_as_hostname_label
- Size: 25.4 KB
- Stars: 49
- Watchers: 4
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
Awesome Lists containing this project
README
= validates_as_hostname_label
Checks for valid hostname labels by looking for:
* Length between 1 and 63 characters long
* Alphanumeric, hyphen, and (optionally) underscore characters
* Labels that don't begin or end with a hyphen or underscore
* Reserved labels
See http://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
== Installation
gem install validates_as_hostname_label
OR
script/plugin install git://github.com/shuber/validates_as_hostname_label.git
== Usage
class Account < ActiveRecord::Base
validates_as_hostname_label :subdomain
end
@account = Account.new
@account.save # false
@account.errors # { :subdomain => 'is required' }
You may optionally pass a :reserved option which should be an array of hostname labels to exclude,
otherwise ValidatesAsHostnameLabel.default_options[:reserved] will be used.
class Account < ActiveRecord::Base
validates_as_hostname_label :subdomain, :reserved => ['www', 'ftp', 'mail', 'pop']
end
@account = Account.new :subdomain => 'www'
@account.save # false
@account.errors # { :subdomain => 'is reserved' }
Also accepts an :allow_underscores option which defaults to false.
class Account < ActiveRecord::Base
validates_as_hostname_label :subdomain, :allow_underscores => true
end
@account = Account.new :subdomain => 'test_ing'
@account.save # true
The standard validation options :if, :unless, and :allow_blank work as well.
== Internationalization
Uses the following I18n keys:
* validates_as_hostname_label.invalid_format
* validates_as_hostname_label.invalid_length
* validates_as_hostname_label.invalid_prefix_or_suffix
* validates_as_hostname_label.reserved
== Note on Patches/Pull Requests
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but
bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.
== Contact
Problems, comments, and suggestions all welcome: shuber@huberry.com