Giter VIP home page Giter VIP logo

domain_name_format_validator's Introduction

Ruby Gem Version

domain_name_format_validator

Ever needed to validate the format of a domain name? This gem will validate any domain name represented in ASCII.

The scope of this gem is deliberately focused on validating the format of domain names. It simply answers the question: "Is this a real domain name?" Using this command, you can make a realistic assessment about whether you want to store a domain name or URL in your database. This gem will tell you:

  1. that a domain is or is not valid
  2. if it's not valid, what the errors are.

Some existing gems for domain name validation use insecure regular expressions. For example if you have the following regex-pattern: ^do_some_checks$, the check can be bypassed by domainn names like: example.com\n<script>alert('xss')</script>. Such a bypass doesn't work with this gem.

Please note that this gem is a fork of https://github.com/dkeener/domain_name_validator which seems to be abandoned

How It Works

To validate a domain name:

    require 'domain_name_format_validator'

    if DomainNameFormatValidator.valid?("example.com")
      # Do something
    end

What about error messages? If a domain isn't valid, it's often desirable to find out why the domain ewasn't valid. To do this, simply pass an array into the "validate" message as the optional second argument.

    require 'domain_name_format_validator'

    errs = DomainNameFormatValidator.errors("example.123")
    unless errs.empty?
      puts("Errors: #{errs.inspect}")
    end

This generates the following output:

Errors: ["The top-level domain (the extension) cannot be numerical"]

This gem should make it easy to validate domain names.

About Domain Names

Domain names provide a unique, memorizable name to represent numerically addressable Internet resources. They also provide a level of abstraction that allows the underlying Internet address to be changed while still referencing a resource by its domain name. The domain name space is managed by the Internet Corporation for Assigned Names and Numbers (ICANN).

The right-most label of a domain name is referred to as the top-level domain, or TLD. A limited set of top-level domain names, and two-character country codes, have been standardized. The Internet Assigned Numbers Authority (IANA) maintains an annotated list of top-level domains, as well as a list of "special use," or reserved, top-level domain names.

Domain names follow some very detailed rules:

  • The maximum length of a domain name is 253 characters.

  • A domain name is divided into "labels" separated by periods. The maximum number of labels is 127.

  • The maximum length of any label within a domain name is 63 characters.

  • No label, including TLDs, can begin or end with a dash.

  • Top-level domain names cannot be all numeric.

  • Domain names may not begin with a period.

  • The characters allowed in labels are a subset of the ASCII character set, consisting of characters a through z, A through Z, digits 0 through 9, and hyphen.

Internationalized Domain Names

What about internationalized domain names? ICANN approved the Internationalized Domain Name (IDNA) system in 2003. This standard allows for Unicode domain names to be encoded into ASCII using Punycode. Essentially, a label may contain "xn--" as a prefix, followed by the Punycode representation of a Unicode string, resulting in domain names such as xn--kbenhavn-54.eu. Note that there are also some approved Unicode TLDs.

The process of rendering an internationalized domain name in ASCII via Punycode is called normalization. This gem will validate a normalized domain name, but not a Unicode domain name. Note, however, that it currently does not validate normalized TLDs against ICANN's list of valid TLDs.

Requirements

This is a Ruby gem with no run-time dependencies on anything else. It has been tested under Ruby 3.0.0p0 but might work with older Ruby versions too.

Install

Installation doesn't get much simpler than this:

gem install domain_name_format_validator

Author

This gem was refactored and relaunched by Wolfgang Hotwagner. The original code was written by David Keener.

YOUR SUPPORT

Every contribution is welcome. Please feel free to open Pull-Requests.

domain_name_format_validator's People

Contributors

armins-toscom avatar dkeener avatar whotwagner avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

armins

domain_name_format_validator's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.