From: Brian Candler Date: 2009-01-26T00:51:13+09:00 Subject: Re: regural expression with not condition. Vamsi Krishna wrote: > validates_format_of :name,:with=>/^['"][ ]*['"]$/ ,:on=> :create P.S. WARNING!! Never use ^ and $ in regular expressions which validate untrusted data. This is because, unlike Perl, they don't mean "match start and end of string", but match start and end of a *line* within the string. You need \A and \z to anchor at the start and end of the string. irb(main):001:0> bad_data = "myname\nrm -rf /*" => "myname\nrm -rf /*" irb(main):002:0> puts "is valid" if bad_data =~ /^[a-z]+$/ is valid => nil irb(main):003:0> puts "is valid" if bad_data =~ /\A[a-z]\z$/ => nil -- Posted via http://www.ruby-forum.com/.