Class: GyomuRuby::Validators::HankakuValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/gyomu_ruby/validators/hankaku_validator.rb

Instance Method Summary collapse

Instance Method Details

#hankaku?(str) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/gyomu_ruby/validators/hankaku_validator.rb', line 10

def hankaku?(str)
  str.blank? || str =~ /\A#{Moji.han}+\Z/
end

#validate_each(record, attribute, str) ⇒ Object



6
7
8
# File 'lib/gyomu_ruby/validators/hankaku_validator.rb', line 6

def validate_each(record, attribute, str)
  record.errors[attribute] << "は、半角文字で入力してください" unless hankaku?(str)
end