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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:38:17+00:00 2026-05-24T06:38:17+00:00

I’m trying to write a method that checks whether a date is valid. It

  • 0

I’m trying to write a method that checks whether a date is valid. It is passed in three Strings: month, day, and year, in order. Month should be from 0-11 instead of 1-12. I have tested the logic of the code in Java and it works. is_int is another method that tests if a String is composed solely of numerical characters. Unfortunately, I am running into problems which I can’t figure out.

function is_int(value) {
   for (i = 0 ; i < value.length ; i++) {
      if ((value.charAt(i) < '0') || (value.charAt(i) > '9')) return false
    }
   return true;
}

function isValidDate(value1:String, value2:String, value3:String)
{
  if (!is_int(value3)) return false;
  if (!is_int(value2)) return false;
  if (!is_int(value1)) return false;
  var v1 = parseInt(value1) + 1;
  var v2 = parseInt(value2);
  var v3 = parseInt(value3);
  if (v1 > 12 || v1 < 1) return false;
  if (v2 > 31 || v2 < 1) return false;
  if (v2 == 31) if (v1 == 2 || v1 == 4 || v1 == 6 || v1 == 9 || v1 == 11) return false;
  if (v1 != 2) return true;
  if (v2 < 29) return true;
  if (v2 == 30) return false;
  if (v3 % 400 == 0)
        return true;
  else if (v3 % 100 == 0)
        return false;
  else if (v3 % 4 == 0)
        return true;
  else
        return false; 
}

My first tester is something that asks for three text inputs and, if the isValidDate function returns false, displays an alert. If not, it forwards to a blank html page. However, I tried this:

function validate() {
  if (!isValidDate("a", "a", "a")) {
  alert("wrong");
  return false;
  }
}

and the alert never displayed and it forwarded every time. Strangely enough, this still happened when I removed the exclamation point in front of isValidDate. I also tried swapping the double quotation marks for single, but that didn’t fix the problem either. The same thing happens with my tester for is_int. I have no idea where I’m going wrong.

  • 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-24T06:38:18+00:00Added an answer on May 24, 2026 at 6:38 am

    I know you didn’t ask for it, but here’s a much more valid way to check for dates, and it handles odd dates more consistently:

    function isValidDate(year, month, day) {
        var d = new Date(parseInt(year,10), parseInt(month, 10)-1, parseInt(day, 10), 0, 0, 0);
        return d.getFullYear() == year &&
               (d.getMonth()+1) == month &&
               d.getDate() == day;
    }
    
    isValidDate("2011", "08", "04"); // true
    isValidDate("bob", "08", "04"); // false
    isValidDate("1979", "1", "1"); // true
    

    Fiddle with it: http://jsfiddle.net/2WJCv/

    Alternate HTML-only link: http://pastehtml.com/view/b2se2lk9k.html

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put

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.