thanks for reply but its unusable bcz value gets blank before validation.

example.
u = User.new
u.birth_date = '31/31/2011'
u.birth_date #=> nil
u.valid? #=> true

u.birth_date = '1/1/2011'
u.birth_date #=> Sat, 01 Jan 2011

On Wed, Feb 1, 2012 at 2:21 PM, Neethu Satheesh <[email protected]>wrote:

> Hi Sandip,
>
> You can provide model level validation for the date as follows.
>
> class User < ActiveRecord::Base
>
> validate :validate_birth_date
>
>  def initialize(args={})
>
>    super
>  end
>
>
>  def validate_birth_date
>      valid_date_format = /<write a regex for the date in the
> appropriate format>/
>      if !birth_date.blank? && !birth_date.match(valid_date_format)
>        errors.add(:base, "Birth date is invalid")
>      end
>  end
>
> end
>
> You can explore more about errors in
>
> http://guides.rubyonrails.org/active_record_validations_callbacks.html#working_with_validation_errors-errors
>
> Thanks,
>
> Neethu
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>


-- 
sαη∂ιρ Rαηѕιηg

---
www.funonrails.com

twitter, github @sandipransing
skype sandip.ransing

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to