How would I use validations to ensure I either received a blank value or
a ten digit number?
If I set validates_length_of :field, :in => 0…10 then that would allow
any value in-between. The allow_nil => true option does not seem to
work.
I’ve also tried using this with some combination of
validates_numericality_of but cannot get it to work.
Any help would be greatly appreciated.
Thanks,
Josh
There might be a some funky validates_* methods I don’t know of, but
typically I define my own validate method whenever I need to do anything
more than basic validations.
To do this, just add a validate method to your AR class; here’s a
snippet from my site:
def validate
is_taken = Member.find_by_email(self.email)
unless (is_taken.nil? || is_taken.id == self.id)
errors.add_to_base(“The email address #{self.email} has
already been registered on DevLists.”)
end
end
HTH.
On Monday, January 30, 2006, at 10:20 PM, Joshua S. wrote:
Any help would be greatly appreciated.
Thanks,
Josh
–
Posted via http://www.ruby-forum.com/.
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
Cheers!
–Dave.