Sha256: 1bf645b10dd9405c734242c161c84ed968218ad95d8cf0917184e4e01b498c8f

Contents?: true

Size: 375 Bytes

Versions: 285

Compression:

Stored size: 375 Bytes

Contents

# An ActiveRecord validator for any url field that you would use with effective_url or otherwise
#
# validates :website, url: true

class UrlValidator < ActiveModel::EachValidator
  PATTERN = /\Ahttps?:\/\/\w+.+\Z/

  def validate_each(record, attribute, value)
    if value.present?
      record.errors.add(attribute, 'is invalid') unless PATTERN =~ value
    end
  end
end

Version data entries

285 entries across 285 versions & 1 rubygems

Version Path
effective_resources-2.27.2 app/validators/url_validator.rb
effective_resources-2.27.1 app/validators/url_validator.rb
effective_resources-2.27.0 app/validators/url_validator.rb
effective_resources-2.26.5 app/validators/url_validator.rb
effective_resources-2.26.4 app/validators/url_validator.rb
effective_resources-2.26.3 app/validators/url_validator.rb
effective_resources-2.26.2 app/validators/url_validator.rb
effective_resources-2.26.1 app/validators/url_validator.rb
effective_resources-2.26.0 app/validators/url_validator.rb
effective_resources-2.25.16 app/validators/url_validator.rb
effective_resources-2.25.15 app/validators/url_validator.rb
effective_resources-2.25.14 app/validators/url_validator.rb
effective_resources-2.25.13 app/validators/url_validator.rb
effective_resources-2.25.12 app/validators/url_validator.rb
effective_resources-2.25.11 app/validators/url_validator.rb
effective_resources-2.25.10 app/validators/url_validator.rb
effective_resources-2.25.9 app/validators/url_validator.rb
effective_resources-2.25.8 app/validators/url_validator.rb
effective_resources-2.25.7 app/validators/url_validator.rb
effective_resources-2.25.6 app/validators/url_validator.rb