Sha256: 0ab92bbaf8bbe92a1aa3ad157dbcac7444fcfd2649046e1ebab8798094d8d97f

Contents?: true

Size: 392 Bytes

Versions: 45

Compression:

Stored size: 392 Bytes

Contents

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

class EffectiveUrlValidator < 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

45 entries across 45 versions & 1 rubygems

Version Path
effective_form_inputs-0.9.8 app/validators/effective_url_validator.rb
effective_form_inputs-0.9.7 app/validators/effective_url_validator.rb
effective_form_inputs-0.9.6 app/validators/effective_url_validator.rb
effective_form_inputs-0.9.5 app/validators/effective_url_validator.rb
effective_form_inputs-0.9.4 app/validators/effective_url_validator.rb