How to compare age with date of birth in Javascript?

Asked

Viewed 995 times

0

I’m having tremendous doubts. Don’t ask me why, but I have to compare the typed age with the date of birth typed to see if they match but I can’t. Please, anyone who can help me I appreciate.

  • 1

    how the date is inserted?

  • 1

    Show how your code is so far.

  • convert the date entered to age.. then compare the age entered with the date result..

1 answer

1

Friend, you can check by subtracting the year of birth by the current year, if the date of birth has not yet passed, subtract 1.

In this link there is an example of part of your question, the person needed to know the age from the date of birth.

How to calculate the age of a person with JS, from the date of birth?

After discovering age using this function, just make a simple if by comparing the ages.

Follow the example http://jsfiddle.net/897d6btq/, hope it helps. :)

Another more elegant solution is to build a Regex.

  • Hi Daniel, you can give examples to make the answer more complete?

  • 1

    Friend, I edited the answer with the example, I hope it helps. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.