forms - PHP - preg_match to validate date format mm/yyyy -
for check of birthday date (format: dd/mm/yyyy) in form i've used code , works fine.
if (!preg_match("/([012]?[1-9]|[12]0|3[01])\/(0?[1-9]|1[012])\/([0-9]{4})/",$date)){ $error[1]= "insert valid date"; }
but when want check date format mm/yyyy , use code, doesn't work anymore. when try example put 33/2014 in input php validation doesn't show error.
if (!preg_match("/(0?[1-9]|1[012])\/([0-9]{4})/",$date2)){ $error[2]= "insert valid date"; }
where go wrong? thank help.
based on tim's checkdate based solution:
the extraction of day, month , year can done using explode as:
list($dd,$mm,$yyyy) = explode('/',$cnt_birthday); if (!checkdate($mm,$dd,$yyyy)) { $error = true; }
Comments
Post a Comment