Date Validation YYYY-MM-DD

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bruno43
    New Member
    • Jun 2007
    • 16

    Date Validation YYYY-MM-DD

    Hi, I am new to ASP and have been using thescripts for a lot of trouble shooting.

    My problem is I am trying to convert a PHP site over to ASP. I have gotten a good grasp on most things. At the current time I am still have trouble with validation in asp.

    The following code is taking an input field and checking to see if it is in YYYY-MM-DD format.

    I am rewritting the ASP code and trying to get the final output to DD/MM/YYYY
    The current format I still want them to use to input the date with will be

    YYYY-MM-DD, I can use the split and rewrite it to DD/MM/YYYY

    So any help or suggestions or links to let me read and/or learn about ASP validation and to rewrite the following code to asp would help greatly.. Thanks!

    [ php ]
    function testDate($idate ) {
    $outime = '';
    $idate = trim($idate);
    if (ereg ("^([0-9]{4})[^0-9]([0-9]{1,2})[^0-9]([0-9]{1,2})$", $idate, $regs)) {
    $dparts=array($ regs[2],$regs[3],$regs[1]);
    } elseif (ereg ("^([0-9]{2})([0-9]{2})([0-9]{2,4})$", $idate, $regs)) {
    $dparts=array($ regs[1],$regs[2],$regs[3]);
    } else {
    $dparts = split('[^0-9]',$idate);
    }
    if (checkdate($dpa rts[0]+0,$dparts[1]+0,$dparts[2]+0)) {
    $indate = strtotime($dpar ts[2].'-'.$dparts[0].'-'.$dparts[1]);
    $outime = date('Y-m-d', $indate);
    }
    return $outime;
    }
    [ /php ]
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    This may not be the most efficient way to go about it, but it might give you a start.

    Code:
    dim mydate
    mydate = "2007-06-15"
    
    Dim arr
    arr = Split( mydate, "-" )
    Access each array member with arr(0), arr(1), arr(2). You should be able to test on them to check if they are numbers and whether they fall in the correct range.

    Comment

    • Bruno43
      New Member
      • Jun 2007
      • 16

      #3
      Originally posted by improvcornartis t
      This may not be the most efficient way to go about it, but it might give you a start.

      Code:
      dim mydate
      mydate = "2007-06-15"
      
      Dim arr
      arr = Split( mydate, "-" )
      Access each array member with arr(0), arr(1), arr(2). You should be able to test on them to check if they are numbers and whether they fall in the correct range.
      Thanks! After I posted it I figured I would do that until someone posted. Thanks for reassuring my idea lol. I had to do some more error testing though in case they did not use two hyphens or did not have the right lengths etc. Appreciate the help!

      Comment

      Working...