Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.93 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Date validation with switch command does not work
  2. function validateDateFormat(day,month,year) {
  3.     alert(month); // this was to ensure month was correct and it is!!
  4.     var maxDay = 0;
  5.     switch(month)
  6.     {
  7.         case 01 :    
  8.         case 03 :
  9.         case 05 :
  10.         case 07 :
  11.         case 08 :
  12.         case 10 :
  13.         case 12 : maxDay = 31; break;
  14.         case 04 :
  15.         case 06 :
  16.         case 09 :
  17.         case 11 : maxDay = 30; break;
  18.         case 02 : if(year%4 == 0) maxDay = 29;
  19.               else maxDay = 28;
  20.               break;    
  21.         //default : return " Invalid month -"; break;    
  22.     }
  23.     alert(maxDay);
  24.     if(day > maxDay) {return " Invalid day -";}
  25.     return "";    
  26. }
  27.        
  28. var num = "9";
  29. if (num == 9)
  30.     alert("true");
  31.        
  32. var num = "9";
  33. switch(num) {
  34.     case 9:
  35.         alert("true");
  36.         break;
  37. }
  38.        
  39. var num = "9";
  40. switch(num) {
  41.     case "9": // string
  42.         alert("true");
  43.         break;
  44. }