{"id":20982205,"url":"https://github.com/alphanodes/valid_hostname","last_synced_at":"2025-05-14T16:31:19.690Z","repository":{"id":62114444,"uuid":"557928968","full_name":"alphanodes/valid_hostname","owner":"alphanodes","description":"Extension to ActiveModel for validating hostnames","archived":false,"fork":false,"pushed_at":"2023-01-11T15:40:51.000Z","size":269,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-14T10:50:31.339Z","etag":null,"topics":["gem","hostname","ruby","validation","validator"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alphanodes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-26T15:10:23.000Z","updated_at":"2024-03-12T18:30:42.000Z","dependencies_parsed_at":"2023-02-09T03:45:55.487Z","dependency_job_id":null,"html_url":"https://github.com/alphanodes/valid_hostname","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphanodes%2Fvalid_hostname","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphanodes%2Fvalid_hostname/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphanodes%2Fvalid_hostname/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alphanodes%2Fvalid_hostname/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alphanodes","download_url":"https://codeload.github.com/alphanodes/valid_hostname/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225302977,"owners_count":17453028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gem","hostname","ruby","validation","validator"],"created_at":"2024-11-19T05:44:50.673Z","updated_at":"2024-11-19T05:44:51.806Z","avatar_url":"https://github.com/alphanodes.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Valid Hostname\n\n* Source: \u003chttps://github.com/AlphaNodes/valid_hostname\u003e\n* Bugs:   \u003chttps://github.com/AlphaNodes/valid_hostname/issues\u003e\n\n[![Run Rubocop](https://github.com/AlphaNodes/valid_hostname/actions/workflows/rubocop.yml/badge.svg)](https://github.com/AlphaNodes/valid_hostname/actions/workflows/rubocop.yml) [![Tests](https://github.com/AlphaNodes/valid_hostname/actions/workflows/tests.yml/badge.svg)](https://github.com/AlphaNodes/valid_hostname/actions/workflows/tests.yml) [![Gem Version](https://badge.fury.io/rb/valid_hostname.png)](http://badge.fury.io/rb/valid_hostname)\n\n## Description\n\nExtension to ActiveModel for validating hostnames and domain names.\n\n## Features\n\n* Adds validation for hostnames to ActiveModel\n* Supports I18n for the error messages\n\n## Installation\n\n### in Gemfile\n\n```Gemfile\ngem 'valid_hostname', '~\u003e 2.0'\n```\n\n### Run bundler\n\n```shell\n  bundle install\n```\n\n## Validations performed\n\n* maximum length of hostname is 255 characters\n* maximum length of each hostname label is 63 characters\n* characters allowed in hostname labels are a-z, A-Z, 0-9 and hyphen\n* labels do not begin or end with a hyphen\n* labels do not consist of numeric values only\n\n## Options\n\n* option to allow for underscores in hostname labels\n* option to require that the last label is a valid TLD (ie. require that the name is a FQDN)\n* option to allow numeric values in the first label of the hostname (exception: the hostname cannot consist of a single numeric label)\n* option to specify a list of valid TLDs\n* options to allow for wildcard hostname in first label (for use with DNS)\n* option to configure error message. verbose: true creates detailed error messages. (only used by )\n\nSee also \u003chttps://www.zytrax.com/books/dns/apa/names.html\u003e\n\n## How to use\n\nSimple usage\n\n```ruby\n  class Record \u003c ActiveRecord::Base\n    validates :name, hostname: true\n  end\n```\n\nWith options\n\n```ruby\n  class Record \u003c ActiveRecord::Base\n    validates :name, hostname: { OPTIONS }\n  end\n```\n\nor static usage\n\n```ruby\n  ValidateHostname.valid?('localhost')\n```\n\nor static usage with options\n\n```ruby\n  ValidateHostname.valid?('localhost', OPTIONS)\n```\n\n## Options and their defaults\n\n* allow_underscore: false\n* require_valid_tld: false\n* valid_tlds: Array of allowed TLDs (can only be used with require_valid_tld: true)\n* allow_numeric_hostname: false\n* allow_wildcard_hostname: false\n* allow_root_label: false\n* verbose: true\n\n## Examples\n\nWithout options\n\n```ruby\n  class Record \u003c ActiveRecord::Base\n    validates :host, hostname: true\n  end\n```\n\n```result\n  \u003e\u003e @record = Record.new :name =\u003e 'horse'\n  \u003e\u003e @record.save\n  =\u003e true\n```\n\n```result\n  \u003e\u003e @record2 = Record.new :name =\u003e '_horse'\n  \u003e\u003e @record2.save\n  =\u003e false\n```\n\nWith :allow_underscore\n\n```ruby\n  class Record \u003c ActiveRecord::Base\n    validates :name, hostname: { allow_underscore: true }\n  end\n```\n\n```result\n  \u003e\u003e @record3 = Record.new :name =\u003e '_horse'\n  \u003e\u003e @record3.save\n  =\u003e true\n```\n\nWith :require_valid_tld\n\n```ruby\n  class Record \u003c ActiveRecord::Base\n    validates :name, hostname: { require_valid_tld: true }\n  end\n```\n\n```result\n  \u003e\u003e @record4 = Record.new :name =\u003e 'horse'\n  \u003e\u003e @record4.save\n  =\u003e false\n```\n\n```result\n  \u003e\u003e @record5 = Record.new :name =\u003e 'horse.com'\n  \u003e\u003e @record5.save\n  =\u003e true\n```\n\nWith :valid_tlds\n\n```ruby\n  class Record \u003c ActiveRecord::Base\n    validates :name, hostname: { :require_valid_tld, valid_tlds: %w[com org net] }\n  end\n```\n\n```result\n  \u003e\u003e @record6 = Record.new :name =\u003e 'horse.info'\n  \u003e\u003e @record6.save\n  =\u003e false\n```\n\nWith :allow_numeric_hostname\n\n```ruby\n  class Record \u003c ActiveRecord::Base\n    validates :name, hostname: { allow_numeric_hostname: false }\n  end\n```\n\n```result\n  \u003e\u003e @record7 = Record.new :name =\u003e '123.info'\n  \u003e\u003e @record7.save\n  =\u003e false\n```\n\nWith :allow_wildcard_hostname\n\n```ruby\n  class Record \u003c ActiveRecord::Base\n    validates :name, hostname: { allow_wildcard_hostname: true }\n  end\n```\n\n```result\n  \u003e\u003e @record8 = Record.new :name =\u003e '*.123.info'\n  \u003e\u003e @record8.save\n  =\u003e true\n```\n\n## Extra validators\n\n### domainname\n\n* sets require_valid_tld: true\n* sets allow_numeric_hostname: true\n* returns error if there is only one label and this label is numeric\n\n## Credits\n\nThis gem is a fork of \u003chttps://github.com/KimNorgaard\u003e.\n\n* [KimNorgaard](https://github.com/KimNorgaard)\n* [alexandermeindl](https://github.com/alexandermeindl/awesome-redmine)\n\n## Copyright\n\nCopyright (c) 2009-2022 Kim Norgaard. See LICENSE for details\nCopyright (c) 2022 Alexander Meindl. See LICENSE for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphanodes%2Fvalid_hostname","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falphanodes%2Fvalid_hostname","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falphanodes%2Fvalid_hostname/lists"}