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? 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. 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! Link to comment https://forums.phpfreaks.com/topic/246100-regular-expression-validation/#findComment-1263897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.