sanny Sin
sanny Sin

Reputation: 1555

Validate on custom words

I have a field in my form, that should not accept some specific words(www, ftp, smtp, etc). Is there any validator that could make some kind of black listed words, that can not be written to db?

Upvotes: 2

Views: 809

Answers (2)

Holin
Holin

Reputation: 1241

You should create your own black list validator. The syntax could be

validates :field, :black_list => {:file_path => "/path/to/words_file"}

Your validator will look to each word in the /path/to/words_file file and add errors on your model if the attribute field contains one black listed word.

Upvotes: 1

emrahbasman
emrahbasman

Reputation: 2013

validates :subdomain, :exclusion => { :in => %w(www ftp smtp) }

ref: rails guide

Upvotes: 4

Related Questions