phily245 Posted August 31, 2011 Share Posted August 31, 2011 Hi, I've got a form where the user submits a date as a text field (as 12-12-2012 for example) called closing. The form submits fine without my regular expression validation, but whenever I try to validate it, it returns the error message I wrote for if no results turn up. Ive tried: <?php if (!preg_match ("[0-9]{2}-[0-9]{2}-[0-9]{4}", $_POST["closing"])) { $_SESSION["report"] = "<b>Error:</b> Date is in the wrong format. It must be dd-mm-yyyy<br />"; $_SESSION["reportcount"] = 0; } ?> and <?php if (!preg_match ("\d{2}-\d{2}-\d{4}", $_POST["closing"])) { $_SESSION["report"] = "<b>Error:</b> Date is in the wrong format. It must be dd-mm-yyyy<br />"; $_SESSION["reportcount"] = 0; } ?> Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/246100-regular-expression-validation/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 31, 2011 Share Posted August 31, 2011 The preg match patterns need delimiters around them. Quote Link to comment https://forums.phpfreaks.com/topic/246100-regular-expression-validation/#findComment-1263887 Share on other sites More sharing options...
phily245 Posted August 31, 2011 Author Share Posted August 31, 2011 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/246100-regular-expression-validation/#findComment-1263897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.