Showing posts with label Validating Date of Birth. Show all posts
Showing posts with label Validating Date of Birth. Show all posts

Friday, May 15, 2009

Different ways of Validating Date of Birth in Model

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

OR

validates_each :date_of_birth do |record, attr, value|
record.errors.add attr, "is not a valid date. You must be at least 18 years old to sign in." if value.blank?
end

OR

def validate
if date_of_birth.month.blank? || date_of_birth.day.blank? || date_of_birth.year.blank?
errors.add_to_base "day, month and year cannot be blank."
end
end