# Date Validation for date\_select

**URL:** <https://discuss.rubyonrails.org/t/date-validation-for-date-select/40419>\
**Category:** rubyonrails-talk\
**Created:** [March 14, 2009, 1:11am UTC](https://discuss.rubyonrails.org/t/date-validation-for-date-select/40419 "2009-03-14T01:11:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [March 14, 2009, 1:11am UTC](https://discuss.rubyonrails.org/t/date-validation-for-date-select/40419/1 "2009-03-14T01:11:25Z")

</div>

I am new to Rails and I am building this website based on the tutorials from a book called Railspace. My problem is I have a form page which accepts the date for a birthdate field

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<div class="form\_row"\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<label for="birthdate"\> Birthdate \</label\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= date\_select :spec, :birthdate, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:start\_year=\>Spec::START\_YEAR, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:end\_year=\>Time.now.year, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:include\_blank=\>true, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:order =\>[:month, :day, :year] %\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</div\>

It works fine when I enter correct dates but when I try entering something like Feb 31 2009 it gives me the following error.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 error(s) on assignment of multiparameter attributes

My parameter variable shows that its being passed as 3 seperate values (that is my understanding please correct me if I am wrong)

{"commit"=\>"Update", "spec"=\>{"city"=\>"Atlanta", "occupation"=\>"Software programmer", "zip\_code"=\>"21312", "birthdate(1i)"=\>"1907", "gender"=\>"Male", "birthdate(2i)"=\>"2", "birthdate(3i)"=\>"31", "first\_name"=\>"Dilbert", "last\_name"=\>"Dilbert", "state"=\>"Georgia"}}

I cannot seem to validate this using the validate method on the controller as I am unable to fetch the values of the parameters. Ive tried using something like

def validate if (birthdate.month==2 && birthdate.day \> 29) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errors.add(:birthdate, "Invalida date") end

but its seems to completely bypass this. It works correctly when i simply type if(birthdate.month==2 ) &nbsp;&nbsp;&nbsp;&nbsp;errors.add(......) but I dont seem to understand why I cannot validate it.

Could someone explain this to me. Thanks in advance.
