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 **.
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 **.
https://name.sijisuru.com/Columns/longname
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