Php regular expression for date

Shibbir

something is wrong in my php regular expression which is not accepting 0 before Month and date. My date formate is MM/DD/YY. It could be 6/6/2014 or 06/06/2014.

if(!empty($datepicker)){
    if(preg_match("/^([0-9]|1[0-2])\/([0-9]|[1-2][0-9]|3[0-1])\/[0-9]{4}$/", $datepicker) !==1)
        $err[] = "Invalid date of birth";
}
Toto

Just add it as:

/^(0?[0-9]|1[0-2])\/(0?[0-9]|[1-2][0-9]|3[0-1])\/[0-9]{4}$/
// ^^                ^^

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related