ArgumentError: multiline anchors (^ or $)

来源:互联网 发布:手机淘宝开店在哪里 编辑:程序博客网 时间:2024/05/17 22:06

报错信息如下

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}
原创粉丝点击