boby lapointe
boby lapointe

Reputation: 535

How do i forbid a character in rails

i would like to forbid "/" from a field.

I read in the doc that it should be something like that:

valid_name_regex = /
validates :name, presence: true, uniqueness: { case_sensitive: true }, format: { with: valid_name_regex }

But i'd like the opposite.

thanks

Upvotes: 0

Views: 141

Answers (1)

dimuch
dimuch

Reputation: 12818

Try something like

validates :name, presence: true, uniqueness: { case_sensitive: true }, format: { with: /^[^\/]+$/ }

Upvotes: 4

Related Questions