――I don't want to have a lot of hashtags like "Rails6" and "Rails6" ...
--Validation that repels double-byte numbers --Validation that repels double-byte hashes
Since it is a validation that does not allow specific characters, describe it with the without option.
Described in the model that inputs the hashtag
models/item.rb
validates :tagbody, format: { without: /[0-9]/, message: 'Please enter the number in half-width' }
By the way, I decided to repel the full-width hash because the subsequent processing is troublesome.
models/item.rb
validates :tagbody, format: { without: /#/, message: ' #Please enter in half-width' }
This time I decided to flip it with validation, but it may be a more friendly design to convert and save. I give up technically ... I also think that the method of making an incremental search is also good, but it is troublesome to mess with JavaScript ...
I would like to challenge if I can afford it.
✔︎
Recommended Posts