[Rails] Japanese longest surname (validation)

Japanese longest surname (validation)

table of contents

  1. Finding the longest surname in Japan
  2. The longest surname in Japan
  3. Validation settings

1. Finding the longest surname in Japan

I was creating an inquiry form for customers. The implementation on the front side is complete, and we have started to implement the validation on the back end. I stopped trying to determine the maximum validation value for ** last name / first name **, which is not always in the contact form item .. Is it okay to use about 15 characters for the maximum value of ** last name / first name **? (Something is moody)

.. If you check it, it seems to be solved! I searched for the longest Japanese surname / first name **.

2. The longest surname in Japan

When I searched for the longest Japanese surname / first name **, We found that the longest surname is ** 5 characters ** (Kanji), and the reading is ** 8 characters **.

Refer to the following site

https://name.sijisuru.com/Columns/longname

3. Validation settings

Now that I know the longest last name, I set the validation as follows: (Since the longest name fluctuates, I decided to set a value with a margin this time.)

app/models/contact.rb


class User < ApplicationRecord
  validates :name_sei, presence: true, length: { maximum: 5 }
  validates :name_mei, presence: true, length: { maximum: 10 }
  validates :name_sei_kana, presence: true, length: { maximum: 8 }
  validates :name_mei_kana, presence: true, length: { maximum: 20 }
end

Until now, I had set the validation value somehow, but through this kind of experience, I learned how to determine the validation value. This completes the validation settings.

Recommended Posts

[Rails] Japanese longest surname (validation)
[Rails] Validation settings and Japanese localization
[rails] Set validation
[Rails5] Rspec -validation-
Rails: Japanese localization of validation messages including devise
[Rails] Japanese localization of validation error message ~ ja.yml ~
[Rails] Customize devise validation
[Rails] Japanese localization using rails-i18n
How to write Rails validation
[Rails] How to use validation
Ruby on Rails validation summary
[Rails] Japanese localization of error messages
Summary of rails validation (for myself)
[Rails] How to write in Japanese
[Rails] Unexpected validation error in devise
Japanese localization of error messages (rails)