A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: php date validation

  1. #1
    anyone else hear that? flashpipe1's Avatar
    Join Date
    Jan 2003
    Location
    Upstate NY
    Posts
    1,929

    php date validation

    I'm building a php form and just want to test a field to see if the date is in the proper format without using a function...

    I know just enough php to get the form working...other than this...got the testing for a proper e-mail address working, but can't get this to work...

    I've tried this, but it's not working...anyone? The format should be MM/DD/YYYY

    Code:
    $result=preg_match("/^(\d{2})/(\d{2})/(\d{4})$/",$date);
    if(!$result){
    	echo "Enter a valid date";
    	exit;
    }
    I also tried:

    Code:
    $result=ereg("^(\d{2})/(\d{2})/(\d{4})+$",$date);
    but I don't know enough about what the punctuation symbols ^,/,(,{ and [ represent to get it working correctly...

    version 4.4.7

    TIA
    Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Try this:
    PHP Code:
    <?PHP
    $date 
    "01/01/2008";

    $result preg_match("/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/",$date);

    if(!
    $result){
        echo 
    "Enter a valid date";
        exit;
    }
    ?>

  3. #3
    Registered User
    Join Date
    Feb 2001
    Posts
    13,039
    Hi,

    so 13/13/2009 is a valid date?

    Musicman

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center