Sha256: cfec69e95786d0a8255851f2ef65c08b7242eee5c7bab06649354d5d7eb16437
Contents?: true
Size: 600 Bytes
Versions: 4
Compression:
Stored size: 600 Bytes
Contents
module OmgValidator module Validators # Checks whether input is a valid URL # Supports the protocols: http, https and ftp # # validates :url, url: true class UrlValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return nil if value.nil? reg = '`.*?((http|ftp|https)://[\w#$&+,\/:;=?@.-]+)[^\w#$&+,\/:;=?@.-]*?`i' unless reg.match(value) record.errors[attribute] = "must be a valid url" end end end end end ActiveModel::Validations::UrlValidator = OmgValidator::Validators::UrlValidator
Version data entries
4 entries across 4 versions & 1 rubygems