user.rb
class User < ActiveRecord::Base
validates :zip_code, format: { with: /^\d{3}\-?\d{4}$/ }
end
Now when I run the application I get the following error:
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?
Because there is a security risk
--^
at the beginning of the line is \ A
--
$ at the end of the line is `` `\ z
I was told to use.
user.rb
class User < ActiveRecord::Base
validates :zip_code, format: { with: /\A\d{3}\-?\d{4}\z/ }
end
Now the error is gone.
Recommended Posts