简体   繁体   中英

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

I am trying to write a regex expressions in PHP to validate two variables:

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

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

How could you write that regex expression for each ?

Thanks

You would be better off using simple php opperators,eg

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

But the issue you will have is some months only have some many days. Use this instead:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM