From: Dara Sanderson Date: 2006-03-30T10:11:02+09:00 Subject: Re: %r regex matching is ignoring my leading zeros First of all, thanks guys for trying to help. I changed my model validation to remove the brackets from around the \d. Still no dice. When I tried it irb as Gabriele did it worked fine though. Just doesn't want to work on the actual form I'm using. I'm afraid I dno't know how to test rails as you have here: > > and in rails: > $cat app\models\foo.rb > class Foo < ActiveRecord::Base > validates_format_of :bar, :with=>%r{^\d{4}$} > end > > >> f=Foo.new > => #""}> > >> f.bar ="0123" > => "0123" > >> f.save > => true > >> f.bar ="012" > => "012" > >> f.save > => false > > what version of ruby are you running? > Maybe it could have been some damn pesky problem like not having > reloaded the model (this happened to me many times :) ? I'm hosted on Dreamhost so they're on version 1.8.2 of ruby. Maybe it does have something to do with conversion to a string. Maybe I'll try and manipulate it in my controller before saving. Any other suggestions? -- Posted via http://www.ruby-forum.com/.