Class: UriValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- UriValidator
- Defined in:
- lib/validates_as_uri/uri_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/validates_as_uri/uri_validator.rb', line 2 def validate_each(record, attribute, value) protocols = [:protocols] || %w(http https) if value !~ %r{^(#{Array.wrap(protocols).join('|')})://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$} record.errors.add(attribute, [:message] || :invalid_uri) end end |