avram icon indicating copy to clipboard operation
avram copied to clipboard

Add validator for URLs

Open jwoertink opened this issue 4 years ago • 0 comments

Would be awesome to have a built-in validator for handling URLs. I think to start, it would just run through URI.parse, and then validate that it has a valid scheme, and hostname.

This can obviously get a bit tricky since doing relative ftp URLs like ftp:///upload could be "valid", but I think it's pretty common to store a standard HTTP url, and having a nice method to validate those would be great.

Maybe something that looks like this?

def validates_url_format(
  attribute : Avram::Attribute,
  scheme : String = "https",
  relative : Bool = false,
  message : String = "must be a URL"
)
end

jwoertink avatar Apr 20 '21 20:04 jwoertink