Jump to content

Regular expression validation


phily245

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.