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 /\A\s/.match?(value)
7 unless options.fetch(:trailing, true)
8 record.errors[attribute] << (options[:message] || I18n.t("validations.trailing_whitespace")) if /\s\z/.match?(value)