Web Analytics Made Easy -
StatCounter Dual format date validation needed - CodingForum

Announcement

Collapse
No announcement yet.

Dual format date validation needed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dual format date validation needed

    Hi,

    I'm looking for a script that will validate a date in at least two formats. Specifically, US (mm/dd/yyyy), and a custom format (yyyy/mm/dd). I'm already stripping out invalid characters, but I need to make sure that the date is in one of the proper formats, and that the day is correct.

    I've tried taking existing scripts and combining them and changing around the formats, but I obviously don't know enough about Javascript to make it work.

    Any help would be very much appreciated.

    Thanks!

  • #2
    www.peterbailey.net/fValidate/

    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

    Comment


    • #3
      Originally posted by beetle
      www.peterbailey.net/fValidate/

      I looked at this site and I'm not sure it's what I'm looking for - I don't see how I can validate a date based upon the format I need, plus installing all of the functions it has available just for this one little instance seems like overkill.

      Nice site, though

      Comment


      • #4
        try this:
        Code:
        function isValidDate(sDate, iFormat){ //iFormat: 0 = mm/dd/yyyy, 1 = yyyy/mm/dd
           var bValid = true;
           var arr = sDate.split('/');
           var d;
        
           switch (iFormat){
             case 0:
               d = new Date(arr[2],arr[0]-1,arr[1]);
               if (d.getDate()!=arr[1] || d.getMonth()!=arr[0]-1 || d.getFullYear()!=arr[2]) bValid=false;
               break;
             case 1:
               d = new Date(arr[0],arr[1]-1,arr[2]);
               if (d.getDate()!=arr[2] || d.getMonth()!=arr[1]-1 || d.getFullYear()!=arr[0]) bValid=false;
               break;
             default:
               bValid=false;
           }
           return bValid;
        }
        Last edited by glenngv; Feb 26, 2004, 02:40 AM.
        Glenn
        vBulletin Mods That Rock!

        Comment

        Working...
        X