1 class WhitespaceValidator < ActiveModel::EachValidator
2 def validate_each(record, attribute, value)
3 unless options.fetch(:leading, true)
4 record.errors[attribute] << (options[:message] || I18n.t("validations.leading_whitespace")) if value =~ /\A\s/
7 unless options.fetch(:trailing, true)
8 record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if value =~ /\s\z/