0

我的模型 abc.rb 中有两个验证

validates_format_of :url, :with => URI::regexp(%w(http https))
validates_format_of :targetUrl, :with => URI::regexp(%w(http https))

validates_format_of :targetUrl 

没有验证输入。无论我输入什么,它都接受。我在其他我有验证的模型上遇到了同样的问题 validates_format_of :website, :with => URI::regexp(%w(http https))。我无法弄清楚为什么验证失败
validates_format_of :targetUrl, :with => URI::regexp(%w(http https))validates_format_of :website, :with => URI::regexp(%w(http https)).

任何提示都会非常有帮助。谢谢

4

1 回答 1

0

您不需要以这种方式指定正则表达式格式。使用类似的东西:

validates :website, format: { with: /(http|https):\/\/[a-zA-Z0-9\-\#\/\_]+[\.][a-zA-Z0-9\-\.\#\/\_]+/i }

显然使用你喜欢的任何正则表达式!

于 2013-09-26T16:30:03.737 回答