简体   繁体   中英

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?

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

参考: 导轨

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM