Sha256: d554c0e07130ed58154a3e87b0ce1b0fa383d0b442eecab1308f570c573190d8
Contents?: true
Size: 970 Bytes
Versions: 5
Compression:
Stored size: 970 Bytes
Contents
module ActiveModel module Validations class UrlValidator < EachValidator class << self attr_accessor :url_regex end # Damn complex regex found on GWave https://wave.google.com/wave/?pli=1#restored:wave:googlewave.com!w%252BsFbGJUukA self.url_regex = /^(?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?$/ def validate_each(record, attribute, value) unless value =~ self.class.url_regex record.errors.add(attribute) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems