Class: PureValidator::Validators::UrlValidator
- Inherits:
-
Object
- Object
- PureValidator::Validators::UrlValidator
- Defined in:
- lib/pure_validator/validators/url_validator.rb
Constant Summary collapse
- URL_REGEXP =
/^(https?:\/\/)?([\w\.-]+)\.([a-z]{2,6}\.?)(\/[\w\.]*)*\/?$/
Class Method Summary collapse
-
.validate(value, url_flag) ⇒ Array
Validates that string is a valid url.
- .validate_options(url_flag) ⇒ Object
Class Method Details
.validate(value, url_flag) ⇒ Array
Validates that string is a valid url
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pure_validator/validators/url_validator.rb', line 8 def self.validate(value, url_flag) return [] if value.nil? errors = [] if url_flag errors << PureValidator::I18n.t('errors.invalid_url') unless !!URL_REGEXP.match(value) else errors << PureValidator::I18n.t('errors.can_not_be_url') if !!URL_REGEXP.match(value) end errors end |
.validate_options(url_flag) ⇒ Object
21 22 23 |
# File 'lib/pure_validator/validators/url_validator.rb', line 21 def self.(url_flag) PureValidator::ArgsValidator.is_boolean!(url_flag, :validation_rule) end |