I used the following.
with_options Conditional validation can be grouped. Enclose it in do end and use it. presence: true Make sure it is not empty. format: Verify that the regular expression described in the with option matches the sent value.
Check if it matches Hiragana, Katakana, and Kanji within the range in Unicode. /[a-z\d]{6,}/i Check if it is case-sensitive and has at least 6 letters or numbers. If you set {6,20}, you can specify that there are no more than 6 characters and no 20 characters. message Describe the message that appears when an error occurs here.
models/user.rb
with_options presence: true, format: { with: /\A[Ah-Hmm-One-龥]+\z/, message: 'Please use double-byte characters for' } do
validates :family_name
validates :first_name
end
validates :password, format: { with: /[a-z\d]{6,}/i, message: "Can use 6 or more alphanumeric characters" }
end
See the format helper section of the Rails guide. https://railsguides.jp/active_record_validations.html List of basic regular expressions https://murashun.jp/blog/20190215-01.html