[RUBY] I tried validation to unify the way hashtags are written

Introduction

Reason to do

――I don't want to have a lot of hashtags like "Rails6" and "Rails6" ...

procedure

--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.

Validation that repels double-byte numbers

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' }

Validation that repels double-byte hashes

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' }

in conclusion

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

I tried validation to unify the way hashtags are written
I tried to explain the method
I tried to summarize the methods used
I tried to implement the Iterator pattern
I tried to summarize the Stream API
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to organize the session in Rails
I tried to set tomcat to run the Servlet.
I tried to organize the cases used in programming
I tried to summarize the state transition of docker
I tried to decorate the simple calendar a little
05. I tried to stub the source of Spring Boot
I tried to reduce the capacity of Spring Boot
I tried to implement the Euclidean algorithm in Java
I tried to implement the like function by asynchronous communication
I tried to introduce Bootstrap 4 to the Rails 6 app [for beginners]
I tried to increase the processing speed with spiritual engineering
I tried to summarize the basics of kotlin and java
[Swift] I tried to implement the function of the vending machine
I tried the Docker tutorial!
I tried the VueJS tutorial!
I tried to summarize the basic grammar of Ruby briefly
I tried to build the environment little by little using docker
I tried to build the environment of WSL2 + Docker + VSCode
I tried the FizzBuzz problem
I tried to verify yum-cron
I tried to summarize object orientation in my own way.
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
I tried to solve the problem of "multi-stage selection" with Ruby
I tried to summarize the words that I often see in docker-compose.yml
[Metal] I tried to figure out the flow until rendering using Metal
I tried to summarize what was asked at the site-java edition-
I tried to illuminate the Christmas tree in a life game
I tried to sort the data in descending order, ascending order / Rails
[Ruby] Tonight, I tried to summarize the loop processing [times, break ...]
I tried to implement the image preview function with Rails / jQuery
Special Lecture on Multi-Scale Simulation: I tried to summarize the 5th
I tried to understand how the rails method "redirect_to" is defined
Special Lecture on Multi-Scale Simulation: I tried to summarize the 8th
I tried to check the operation of gRPC server with grpcurl
I tried to understand how the rails method "link_to" is defined
[Java] I tried to make a maze by the digging method ♪
I tried to move the Java compatible FaaS form "Fn Project"
I tried to display the calendar on the Eclipse console using Java.
Special Lecture on Multi-Scale Simulation: I tried to summarize the 7th
I tried to solve the problem of Google Tech Dev Guide
I tried to chew C # (indexer)
I tried to summarize iOS 14 support
I tried to interact with Java
I tried the Java framework "Quarkus"
[Rails] I tried deleting the application
The story I wanted to unzip
I tried to summarize Java learning (1)
I tried to understand nil guard
I tried to summarize Java 8 now
I tried to chew C # (polymorphism: polymorphism)
I tried to explain Active Hash
I tried connecting the dot counter to the MZ platform by serial communication
I tried to summarize the key points of gRPC design and development
[Ruby] I tried to diet the if statement code with the ternary operator
I tried to solve the tribonacci sequence problem in Ruby, with recursion.