INVALID_CHARS = "\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff".freeze
def validate_each(record, attribute, value)
- if value =~ /[#{INVALID_CHARS}]/
- record.errors[attribute] << (options[:message] || "contains invalid chars")
- end
+ record.errors[attribute] << (options[:message] || "contains invalid chars") if value =~ /[#{INVALID_CHARS}]/
end
-end
\ No newline at end of file
+end
INVALID_URL_CHARS = "/;.,?%#".freeze
def validate_each(record, attribute, value)
- if value =~ /[#{INVALID_URL_CHARS}]/
- record.errors[attribute] << (options[:message] || I18n.t("validations.invalid chars", :invalid_chars => INVALID_URL_CHARS))
- end
+ record.errors[attribute] << (options[:message] || I18n.t("validations.invalid chars", :invalid_chars => INVALID_URL_CHARS)) if value =~ /[#{INVALID_URL_CHARS}]/
end
-end
\ No newline at end of file
+end
class LeadingWhitespaceValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
- if value =~ /\A\s/
- record.errors[attribute] << (options[:message] || I18n.t("validations.leading whitespace"))
- end
+ record.errors[attribute] << (options[:message] || I18n.t("validations.leading whitespace")) if value =~ /\A\s/
end
-end
\ No newline at end of file
+end
class TrailingWhitespaceValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
- if value =~ /\s\z/
- record.errors[attribute] << (options[:message] || I18n.t("validations.trailing whitespace"))
- end
+ record.errors[attribute] << (options[:message] || I18n.t("validations.trailing whitespace")) if value =~ /\s\z/
end
-end
\ No newline at end of file
+end