ArgumentError: multiline anchors (^ or $)

報錯信息如下

ArgumentError: The provided regular expression is using multiline anchors (^ or $), which may present a security risk. Did you mean to use \A and \z, or forgot to add the :multiline => true option?

報錯原因如下

我寫了個郵箱驗證,正則中用到了標誌一行開頭結尾 (^) 和 ($) 
validates :email, :presence => true, :uniqueness => true, :format=> {:with => /^\w+@\w+\.\w+$/},:length => {:maximum => 40}

解決方法如下

validates :email, :presence => true, :uniqueness => true, :format=> {:with => /^\w+@\w+\.\w+$/,:multiline => true},:length => {:maximum => 40}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章