Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem in Javascript

Problem in Javascript

Scheduled Pinned Locked Moved ASP.NET
javascripthelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janani13
    wrote on last edited by
    #1

    Hi all, Im using JS to check the date and month validation. If i give 08-14-1949 the month value return as 0 not as 8 and the same problem for 09-14-1983. These two month value is considered as 0. I cant resolve it. Please help me. Code.

        function checkyear(source, arg) {
            var txtDOB = arg.Value;
            var birthdate = txtDOB.split("/");
            var yearvalue = parseInt(birthdate\[2\]);
            var MonthValue = parseInt(birthdate\[0\]);
            var DayValue = parseInt(birthdate\[1\]);
            var date = new Date();
            alert(yearvalue);
            alert(MonthValue);
            alert(DayValue);
            var CurrentYear = date.getFullYear();
            if (MonthValue < 1 || MonthValue > 12) {
                alert(MonthValue);
                source.errormessage = "Please enter a valid Date of birth";
                arg.IsValid = false;
                return;
            }
            if (DayValue < 1 || DayValue > 31 || (MonthValue == 2 && DayValue > daysInFebruary(yearvalue))) {
    
                alert(DayValue);
                source.errormessage = "Please enter a valid Date of birth";
                arg.IsValid = false;
                return;
    
    
            }
            if (yearvalue >= CurrentYear - 13) {
    
                source.errormessage = "Your age should be greater than 13.";
                arg.IsValid = false;
                return;
            }
            else if ((yearvalue <= 1900) || (yearvalue >= CurrentYear)) {
                source.errormessage = "Please enter a valid Date of birth";
                arg.IsValid = false;
                return;
            }
            else {
                arg.IsValid = true;
            }
        }
        function daysInFebruary(year) {
            // February has 29 days in any year evenly divisible by four,
            // EXCEPT for centurial years which are not also divisible by 400.
    
            return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
            alert(((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
        }
    
    A 1 Reply Last reply
    0
    • J janani13

      Hi all, Im using JS to check the date and month validation. If i give 08-14-1949 the month value return as 0 not as 8 and the same problem for 09-14-1983. These two month value is considered as 0. I cant resolve it. Please help me. Code.

          function checkyear(source, arg) {
              var txtDOB = arg.Value;
              var birthdate = txtDOB.split("/");
              var yearvalue = parseInt(birthdate\[2\]);
              var MonthValue = parseInt(birthdate\[0\]);
              var DayValue = parseInt(birthdate\[1\]);
              var date = new Date();
              alert(yearvalue);
              alert(MonthValue);
              alert(DayValue);
              var CurrentYear = date.getFullYear();
              if (MonthValue < 1 || MonthValue > 12) {
                  alert(MonthValue);
                  source.errormessage = "Please enter a valid Date of birth";
                  arg.IsValid = false;
                  return;
              }
              if (DayValue < 1 || DayValue > 31 || (MonthValue == 2 && DayValue > daysInFebruary(yearvalue))) {
      
                  alert(DayValue);
                  source.errormessage = "Please enter a valid Date of birth";
                  arg.IsValid = false;
                  return;
      
      
              }
              if (yearvalue >= CurrentYear - 13) {
      
                  source.errormessage = "Your age should be greater than 13.";
                  arg.IsValid = false;
                  return;
              }
              else if ((yearvalue <= 1900) || (yearvalue >= CurrentYear)) {
                  source.errormessage = "Please enter a valid Date of birth";
                  arg.IsValid = false;
                  return;
              }
              else {
                  arg.IsValid = true;
              }
          }
          function daysInFebruary(year) {
              // February has 29 days in any year evenly divisible by four,
              // EXCEPT for centurial years which are not also divisible by 400.
      
              return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
              alert(((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
          }
      
      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Why do you require all this code?? Why dont you use

      var myDate=new Date();
      myDate.setFullYear(2000,0,23); //to set date (23th January 2000)

      Now you can use

      myDate.getMonth();
      myDate.getDay();

      etc.. and make your life easy. On your case the Culprit is parseInt. It has a bug, if you parseInt(08) it returns 0 rather than 8. The easy fix would be

      parseInt(08 * 1)

      . This will fix your issue. cheers.. :thumbsup:

      Abhishek Sur


      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

      **Don't forget to click "Good Answer" if you like to.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups