time regex for 12hr am and pm

前端 未结 1 1499
误落风尘
误落风尘 2021-01-16 10:03

I have made this regex

 ^(00|0[0-9]|1[012]):[0-5][0-9]? ((a|p)m|(A|P)M)$

but the problem is it is accepting 00:00 am which i dont want to

1条回答
  •  北海茫月
    2021-01-16 10:11

    You could use:

    Regex.IsMatch(input, @"^(0[1-9]|1[0-2]):[0-5][0-9] [ap]m$", RegexOptions.IgnoreCase);
    

    0 讨论(0)
提交回复
热议问题