No commit activity in last 3 years
No release in over 3 years
Add Japanese validators
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

< 6.0, >= 4.2
 Project Readme

Validate Japanese

Build Status Gem Version

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 "0-οΌ™"
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: