I want a regular expression to use in preg_match to check whether or not a date is in the pattern DD/MM/YYYY. I tried the code below, but it didn’t work:
preg_match("#^[1-31]*1[1-12]*1[1950-2013]?#", $date);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use
preg_match("/^\d{1,2}\/\d{1,2}\/\d{4}/",$date);however a regex isn’t well-suited for this task because there you will still need to perform additional validation (“9999” is a valid year, for example). I think instead you may want to take a look atdate_parse_from_format(), like:See Convert String To date in PHP for more information.