Class: Validatious::Validators::UrlValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Validatious::Validators::UrlValidator
- Defined in:
- lib/validatious/validators/url_validator.rb
Overview
Active Model Url Validator
Constant Summary collapse
- IPv4_PART =
0-255
/\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]/- REGEX =
%r{ \A https?:// # http:// or https:// ([^\s:@]+:[^\s:@]*@)? # optional username:pw@ ( (xn--)?[a-z0-9]+([-.][a-z0-9]+)*\.[a-z]{2,6}\.? | # domain (including Punycode/IDN)... #{IPv4_PART}(\.#{IPv4_PART}){3} ) # or IPv4 (:\d{1,5})? # optional port ([/?]\S*)? # optional /whatever or ?whatever \Z }iux
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
18 19 20 |
# File 'lib/validatious/validators/url_validator.rb', line 18 def validate_each(record, attribute, value) record.errors.add(attribute, :invalid_url, ) if value.to_s !~ REGEX end |