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

前端 未结 9 825
孤街浪徒
孤街浪徒 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:02

    If you really like to use regex, you need to put ^ and $, like

    "^(0?[1-9]|1[012])$"

    it will not match 13, 14 ....

提交回复
热议问题