You can use a custom validator for that purpose:
class Book < ActiveRecord::Base
attr_accessible :isbn
validate :check_length
def check_length
unless isbn.size == 10 or isbn.size == 13
errors.add(:isbn, "length must be 10 or 13")
end
end
end