SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast HARS's Avatar
    Join Date
    Jun 2001
    Location
    Stockholm, Sweden
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    correct date script

    hello, i found this script on the web, it checks if the date has been entered correctly, but the problem is that it wants the date in DD-MM-YYYY format, and i would like to have it in YYYY-MM-DD format, and since i dont know anything about javascript i ask for you help on this simple (i guess) problem...
    cheers!
    /Måns


    <script language="JavaScript">
    <!--
    function isValidDate()
    {
    var dateStr = document.myForm.date.value;
    var strErr=0;
    var datename = new Date();
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
    var matchArray = dateStr.match(datePat);
    if (matchArray == null)
    {
    alert("Date is not in a valid format.")
    strErr=1;
    return false;
    }
    month = matchArray[3];
    day = matchArray[1];
    year = matchArray[4];
    if (month < 1 || month > 12)
    {
    alert("Month must be between 1 and 12.");
    strErr=1;
    return false;
    }
    if (day < 1 || day > 31)
    {
    alert("Day must be between 1 and 31.");
    strErr=1;
    return false;
    }
    if ((month==4 || month==6 || month==9 || month==11) && day==31)
    {
    alert("Month "+month+" doesn't have 31 days!")
    strErr=1;
    return false
    }
    if (month == 2)
    {
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day>29 || (day==29 && !isleap))
    {
    alert("February " + year + " doesn't have " + day + " days!");
    strErr=1;
    return false;
    }
    }
    alert("That was a correct date. \nHave another go :=)")
    return false;
    }
    //-->
    </script>

  2. #2
    SitePoint Enthusiast HARS's Avatar
    Join Date
    Jun 2001
    Location
    Stockholm, Sweden
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    got it working

    it's ok, i put my lazy *** to work and got it the script working...
    cheers!
    /Måns


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •