Class: ActiveModel::Validations::JapaneseValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::JapaneseValidator
- Defined in:
- lib/validate_japanese/japanese_validator.rb
Constant Summary collapse
- PREFIX =
"\\A"
- SUFFIX =
"\\z"
- KUHAKU =
"\\s"
- CHOONPU =
"ー-"
- HANKAKU_CHOONPU =
"\\-"
- ALPHABET =
"a-zA-Z"
- ZENKAKU_ALPHABET =
"a-zA-Z"
- HIRAGANA =
"ぁ-ん"
- KATAKANA =
"ァ-ン"
- HANKAKU_KANA =
"ァ-ン゙゚"
- KANJI =
"一-龠々"
- SUJI =
"0-9"
- ZENKAKU_SUJI =
"0-9"
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/validate_japanese/japanese_validator.rb', line 19 def validate_each(record, attribute, value) keys, regexp = build_regexp() unless value.to_s.match? regexp if [:message] record.errors.add(attribute, [:message]) else record.errors.add(attribute, :invalid_japanese, kind: available_kind(keys, concat: [:concat])) end end end |