开发者

Rails: How to validate for multiple exact lengths of a string?

开发者 https://www.devze.com 2023-03-22 01:19 出处:网络
I want to ch开发者_如何学Ceck a string for exactly 8 or 10 characters. Is there a possibility with validates_length_of?Just do this

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

精彩评论

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