Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:23:44+00:00 2026-06-13T22:23:44+00:00

I have a form where i’m trying to validate that a field called birthday

  • 0

I have a form where i’m trying to validate that a field called “birthday” is not blank, and that the date is a valid date format that the Chronic gem can parse. I always get the error message “Birthday is invalid”. I’ve been trying a simple format “10/10/2010”.

How can i validate that the birthday field is of a format that chronic can parse?

User.rb model

class User < ActiveRecord::Base

  validates :birthday, :presence => true
  validate :birthday_is_date
  validate :position, :presence => true

  # validate the birthday format
  def birthday_is_date
    errors.add(:birthday ,Chronic.parse(birthday)) # testing to see the value of :birthday
    errors.add(:birthday, "is invalid test message") if ((Chronic.parse(:birthday) rescue ArgumentError) == ArgumentError)
  end
end

contacts_controller.rb

# POST /contacts/1/edit
    # actually updates the users data
    def update_user
        @userProfile = User.find(params[:id])

        respond_to do |format|
            if @userProfile.update_attributes(params[:user])
                format.html {
                    flash[:success] = "Information updated successfully"
                    redirect_to(profile_path)
                }
            else 
                format.html {
                    flash[:error] = resource.errors.full_messages

                    render :edit
                }
            end
        end
    end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:23:45+00:00Added an answer on June 13, 2026 at 10:23 pm

    Your birthday_is_date validation always adds an error on the first line. It should be written as follows:

    def birthday_is_date
      errors.add(:birthday, "is invalid") unless Chronic.parse(birthday)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form where user submits field. Field can have letters, numbers, and punctuation.
I have form with checkboxes loaded from database (I use entity field type). Checkboxes
I have form object that I set to request in GET request handler in
I have form and form text field which generates dynamically using JSP. And I'm
I have form data that I insert into a database when the user clicks
i have form and i am using jquery validate jquery.validate.pack.js its work fine when
i have form that has multiple input text boxes, Which has got some text
I have form where a particular field requires both server side and client side
I have form that I want people to fill out but if they are
I have form for file uploading in my website that i check mime-type of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.