I want to validate a number :value to be within 1 or 2
:value
validates :value, :format => { :with => /1|2/, :message => \"Select number..\" }
You're looking for validates_inclusion_of:
validates_inclusion_of :value, :in => [1, 2], :message => "Select one of %{value}"
You can also use the (fairly new) shothand form and a Range instead of an Array:
validates :value, :inclusion => { :in => 1..2 }