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 5935925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:19:30+00:00 2026-05-22T15:19:30+00:00

I am creating a user signup form, and I am adding date of birth

  • 0

I am creating a user signup form, and I am adding date of birth to the required fields.

I have scoured google, github and stackoverflow for a good date of birth (date) regex, and found this:

user.rb

DateRegex = /^\d{4}-\d{2}-\d{2}/

validates_format_of :date_of_birth, :with => DateRegex

new.html.erb

<%=label_tag :date_of_birth %>
<%=f.text_field :date_of_birth %> 

(I know that this will allow some bogus birth dates, but I prefer not to install anything like validate timeliness at this point.)

However, when testing the date of birth, it doesn’t seem to enforce the 4-2-2 in the regex. It allows 2-2-2 sometimes, 2-4-2, 2-2-4, and it allows hyphens and slashes…help please?

Also, if necessary, how to I use 3 text fields and have it enter into one mysql date_of_birth column?

  • 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-05-22T15:19:31+00:00Added an answer on May 22, 2026 at 3:19 pm

    You could always just use Date.parse to make your life a lot easier. If it can be parsed, it’s probably a valid date:

    validates_each :date_of_birth do |record, attr, value|
      begin
        Date.parse(value)
      rescue
        record.errors.add(attr, "Invalid date")
      end
    end
    

    This has the advantage of rejecting things like 99-99-99 and February 30th.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created my own signup form and creating the user using the Membership class.
I have just finished creating my signup form and now ready to insert data
I have a little checkbox on a signup form im creating which 'must' be
I'm creating a user form that requires the functionality for people to come back
I am creating an user registration form using jsp,in which there is an option
I am having troubling creating a nested signup form for users that are using
I'm building a prelaunch signup site with this tutorial. http://railsapps.github.com/tutorial-rails-prelaunch-signup.html . After a user
I have a form in rails 3.2 for creating users in a company. Each
I'm creating a user registration form. I designed the UI interface through story board
I am creating a method to validate my login fields (user name and password).

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.