Rails4 : model validates "format with" regex for slug column

Viewed 1266

My model has slug with friendly ID gem, and sometimes user inputs only-digit slug and has problem with accessing pages. Then I want to change model validation except only-digit and some special chars.

Here is the current model validates

validates :slug, presence: true, length: { maximum: 200 }, uniqueness: true,
        format: {with: /\A[^\s!#$%^&*()()=+;:'"\[\]\{\}|\\\/<>?,]+\z/, message: :invalid_slug}

How can I add here??

EXAMPLE:

Current:

'123' => valid
'abc' => valid
'adb?&' => invalid

New:

'123' => invalid
'abc' => valid
'adb?&' => invalid

cheers

1 Answers
Related