在PHP中验证给定日期的日和月的正则表达式


Regex to validate day and Month of a given day in PHP

我试图在PHP中编写一个正则表达式来验证两个变量:

1)。$months range from (1 - 31)

2)。$days range from (1 - 12)

你怎么能写出每个正则表达式呢?

谢谢

您最好使用简单的php操作符,例如

if( $months > 0 && $months < 32 )

但是你会遇到的问题是有些月只有一些多天。用这个代替:

http://www.php.net/manual/en/function.checkdate.php