Rails: How to validate for multiple exact lengths of a string?
I want to ch开发者_如何学Ceck a string for exactly 8 or 10 characters.
Is there a possibility with validates_length_of?
Just do this
class Foo
validate :check_length
def check_length
unless column.size == 8 or column.size == 10
errors.add(:column, "length must be 8 or 10")
end
end
end
You get the idea.
精彩评论