1

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";
}

1 Answer 1

5

Just add it as:

/^(0?[0-9]|1[0-2])\/(0?[0-9]|[1-2][0-9]|3[0-1])\/[0-9]{4}$/
// ^^                ^^
Sign up to request clarification or add additional context in comments.

1 Comment

@creativeartbd I like to use Debuggex to understand regular expressions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.