Ruby

URL Validation in Ruby

When it comes to validation, I don’t like to re-invent the wheel. Many programming languages have built-in modules for common types of data, such as a URL.

In Ruby, we have the URI module which is often used to generate, parse, and manipulate a URI. It has a method URI.parse which accepts a string and creates an instance of a URI.

For a time, I thought this was a decent approach to use. You could validate a string as a URL doing something like: