简体   繁体   English

PHP正则表达式验证生日

[英]php regex validate birthdate

Im having difficulties figuring out how to do the following preg_match in php. 我在弄清楚如何在php中执行以下preg_match遇到困难。 I have a HTML form where the user can enter his or hers birthdate by day, month & year. 我有一个HTML表单,用户可以在其中按天,月和年输入他或她的生日。

How do i validate the following Day: make sure it's a number between 1 and 31, actually between 01 and 31 Month: make sure it's a number between 1 and 12, actually between 01 and 12 Year: make sure it's a number between 1800 and 2012, actually between 1800 and 2012 我如何验证第二天:确保它是1到31之间的数字,实际上是01到31个月之间:确保它是1到12之间的数字,实际上是01到12年之间:确保它是1800到12之间的数字2012年,实际上是1800年至2012年之间

if (preg_match( ????? )) {
     echo " SUCCESS";
} else { 
     echo " ERROR";
} 

Thanks... 谢谢...

Checkdate needs 3 different parameters, for validating one input with preg_match, use pattern: Checkdate需要3个不同的参数,用于使用preg_match验证一个输入,请使用pattern:

(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((?|19|20)\d\d)

it validates correct date in style dd-mm-yyy and dd.mm.yyyy and dd/mm/yyyy and if you want, it also parses values out for each parameter 它以dd-mm-yyy和dd.mm.yyyy以及dd / mm / yyyy格式验证正确的日期,并且如果需要,还可以解析每个参数的值

您可以通过checkdate()函数执行此操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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