]> git.openstreetmap.org Git - rails.git/blobdiff - app/validators/trailing_whitespace_validator.rb
Create invalid_char validators and apply to models
[rails.git] / app / validators / trailing_whitespace_validator.rb
diff --git a/app/validators/trailing_whitespace_validator.rb b/app/validators/trailing_whitespace_validator.rb
new file mode 100644 (file)
index 0000000..bb34ef4
--- /dev/null
@@ -0,0 +1,7 @@
+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
+  end
+end
\ No newline at end of file