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

  • Home
  • SEARCH
  • 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 6023295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:59:01+00:00 2026-05-23T03:59:01+00:00

How to validate user input date is the last day of the month using

  • 0

How to validate user input date is the last day of the month using javascript?

  • 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-23T03:59:01+00:00Added an answer on May 23, 2026 at 3:59 am

    (Update: See the final example at the bottom, but the rest is left as background.)

    You can add a day to the Date instance and see if the month changes (because JavaScript’s Date object fixes up invalid day-of-month values intelligently), e.g.:

    function isLastDay(dt) {
        var test = new Date(dt.getTime()),
            month = test.getMonth();
    
        test.setDate(test.getDate() + 1);
        return test.getMonth() !== month;
    }
    

    Gratuitous live example

    …or as paxdiablo pointed out, you can check the resulting day-of-month, which is probably faster (one fewer function call) and is definitely a bit shorter:

    function isLastDay(dt) {
        var test = new Date(dt.getTime());
        test.setDate(test.getDate() + 1);
        return test.getDate() === 1;
    }
    

    Another gratuitous live example

    You could embed more logic in there to avoid creating the temporary date object if you liked since it’s really only needed in February and the rest is just a table lookup, but the advantage of both of the above is that they defer all date math to the JavaScript engine. Creating the object is not going to be expensive enough to worry about.


    …and finally: Since the JavaScript specification requires (Section 15.9.1.1) that a day is exactly 86,400,000 milliseconds long (when in reality days vary in length a bit), we can make the above even shorter by adding the day as we :

    function isLastDay(dt) {
        return new Date(dt.getTime() + 86400000).getDate() === 1;
    }
    

    Final gratuitous example

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

Sidebar

Related Questions

I am using regular expressions to validate user input. The following code collects a
How can I validate the user input by using scanf. Right now I have
I'm trying to validate user input by using the QString::toDouble() function. The documentation says
i want to validate user input for alphanumeric characters and for that im using
I want to validate user input on a Web Form, like valid numbers, date
I'm trying to validate user input on a text parameter using a VB function.
I need to validate a user input using getch() only to accept numeric input
I'm trying to validate user input, which is just comma separated numbers. I'd like
I'd like to validate user input with regular expression in Django Admin CharField... How
I need to validate the user input of a JSpinner , and if invalid,

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.