psharma
psharma

Reputation: 1289

How to limit a form field to certain range of number in rails

I have these two conditions and confused as to should I go with regex or if there is a better rails helper method to do so

What i want to do is

field1: to have any number between 1-31
field2: to have any number between 1-5

This is to be checked when create action is invoked.

Any guidance is appreciated here.

Upvotes: 1

Views: 1154

Answers (1)

shayonj
shayonj

Reputation: 910

Try this in your respective model

validates :field1, :inclusion => 1..31, on => :create
validates :field2, :inclusion => 1..5, on => :create

HTH

Upvotes: 1

Related Questions