How can I use a regular expression to validate month input?

前端 未结 9 824
孤街浪徒
孤街浪徒 2020-12-11 00:31

I am setting up this example Perl snippet to validate for months in a date:

Some scenarios I want to accept are:

MM M

#!/usr/bin/perl
use str         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 01:05

    To give you hint - month number "120" also matches in your version :-)

    Change:

    my $month = "(0[1-9]|1[012])";
    

    to

    my $month = /^(0[1-9]|1[012])$/;
    

    and then play more with it

提交回复
热议问题