How would i apply an if statement in an input field if i want the input to be exactly in MM/DD/YYYY format? Any other input that is different from this format i would echo out an error statement.
Share
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 a regular expresion for that:
The
#are just preg_match delimiters. The^and$mark start and end for the subject to match. And each\dis a placeholder which will match a decimal. The/are literal slashes which preg_match will test for.You could also add
(capture)groups to test the individual decimal blocks for conformity. I would do that separately to check for alternating formats. But for your purposes, it could be: