]> git.openstreetmap.org Git - rails.git/blob - app/validators/utf8_validator.rb
Merge remote-tracking branch 'upstream/pull/1926'
[rails.git] / app / validators / utf8_validator.rb
1 ##
2 # validation method to be included like any other validations methods
3 # in the models definitions. this one checks that the named attribute
4 # is a valid UTF-8 format string.
5 class Utf8Validator < ActiveModel::EachValidator
6   def validate_each(record, attribute, value)
7     record.errors.add(attribute, " is invalid UTF-8") unless UTF8.valid? value
8   end
9 end