Regular Expression to match a valid day in a date

后端 未结 10 1740
别那么骄傲
别那么骄傲 2020-12-11 01:45

I need help coming up with a regex to make sure the user enters a valid date The string will be in the format of mm/dd/yyyy

Here is what I have come up

10条回答
  •  既然无缘
    2020-12-11 02:15

    Is regular expression a must? If not, you better off using a different approach, such as DateTime::Format::DateManip

    my @dates = (
        '04/23/2009',
        '01/22/2010 6pm',
        'adasdas',
        '1010101/12312312/1232132'
    );
    
    for my $date ( @dates ) 
    {
        my $date = DateTime::Format::DateManip->parse_datetime( $date );
        die "Bad Date $date"  unless (defined $date);
        print "$dt\n";
    }
    

提交回复
热议问题