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.19.10 app/validators/url_validator.rb
effective_resources-2.19.9 app/validators/url_validator.rb
effective_resources-2.19.8 app/validators/url_validator.rb
effective_resources-2.19.7 app/validators/url_validator.rb
effective_resources-2.19.6 app/validators/url_validator.rb
effective_resources-2.19.5 app/validators/url_validator.rb
effective_resources-2.19.4 app/validators/url_validator.rb
effective_resources-2.19.3 app/validators/url_validator.rb
effective_resources-2.19.2 app/validators/url_validator.rb
effective_resources-2.19.1 app/validators/url_validator.rb
effective_resources-2.19.0 app/validators/url_validator.rb
effective_resources-2.18.5 app/validators/url_validator.rb
effective_resources-2.18.4 app/validators/url_validator.rb
effective_resources-2.18.3 app/validators/url_validator.rb
effective_resources-2.18.2 app/validators/url_validator.rb
effective_resources-2.18.1 app/validators/url_validator.rb
effective_resources-2.18.0 app/validators/url_validator.rb
effective_resources-2.17.5 app/validators/url_validator.rb
effective_resources-2.17.4 app/validators/url_validator.rb
effective_resources-2.17.3 app/validators/url_validator.rb