Rails custom validation based on a regex?

前端 未结 3 2038
既然无缘
既然无缘 2020-12-16 19:20

I have the following regex that I use in my routes.rb for /type-in-something-here

# A-Z, a-z, 0-9, _ in the middle but never starting or ending in a _
# At l         


        
3条回答
  •  暖寄归人
    2020-12-16 19:57

    validates :name, format: { with: /\A[a-zA-Z]+\z/,
    message: "Only letters are allowed" }
    

提交回复
热议问题