Validate Japanese
This gem adds the capability of validating Japanese to ActiveRecord. π
Getting Started
Add this line to your applicationβs Gemfile:
gem 'validate_japanese'
Add a validation rule to your model:
class User < ApplicationRecord
validates :name, japanese: true
end
I18n error message:
User.new(name: 'invalid name').tap(&:valid?)
# => Name γ«δ½Ώγγζεγ―γ²γγγͺγ«γΏγ«γεθ§γ«γζΌ’εζ°εε
¨θ§ζ°εγ§γγ
Usage
# hiragana katakana hankaku_kana kanji suji zenkaku_suji "γΌοΌ" + "-"
validates :name, japanese: true
user.errors.full_messages
# => Name γ«δ½Ώγγζεγ―γ²γγγͺγ«γΏγ«γεθ§γ«γζΌ’εζ°εε
¨θ§ζ°εγ§γγ
# hiragana "γ-γ" + "γΌοΌ"
validates :name, japanese: {hiragana: true}
user.errors.full_messages
# => Name γ«δ½Ώγγζεγ―γ²γγγͺγ§γγ
# katakana "γ‘-γ³" + "γΌοΌ"
validates :name, japanese: {katakana: true}
user.errors.full_messages
# => Name γ«δ½Ώγγζεγ―γ«γΏγ«γγ§γγ
# hankaku_kana "ァ-οΎοΎοΎ" + "-"
validates :name, japanese: {hankaku_kana: true}
user.errors.full_messages
# => Name γ«δ½Ώγγζεγ―εθ§γ«γγ§γγ
# kanji "δΈ-ιΎ γ
"
validates :name, japanese: {kanji: true}
user.errors.full_messages
# => Name γ«δ½Ώγγζεγ―ζΌ’εγ§γγ
# suji "0-9"
validates :name, japanese: {suji: true}
user.errors.full_messages
# => Name γ«δ½Ώγγζεγ―ζ°εγ§γγ
# zenkaku_suji "οΌ-οΌ"
validates :name, japanese: {zenkaku_suji: true}
user.errors.full_messages
# => Name γ«δ½Ώγγζεγ―ε
¨θ§ζ°εγ§γγ
# hiragana katakana "γ-γ" + "γ‘-γ³" + "γΌοΌ"
validates :name, japanese: {only: %i(hiragana katakana)}
user.errors.full_messages
# => Name γ«δ½Ώγγζεγ―γ²γγγͺγ«γΏγ«γγ§γγ
# japanese "γγ"
validates :name, japanese: {concat: 'γγ'}
user.errors.full_messages
# => Name γ«δ½Ώγγζεγ―γ²γγγͺγ«γΏγ«γεθ§γ«γζΌ’εζ°εε
¨θ§ζ°εγγγ§γγ
Implementation
TODO
Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features