开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜