preg_match - date format pattern - STRICT

I think I have finally gone nutty… regular expressions just will not click for me. :frowning:

I need a pattern that strictly limits the user to:

MM/DD/YYYY format

0or1 0-2 / 0-3 0-9 / 2 0or1 0-9 0-9

Does that make any sense? I would appreciate some insight on putting this badboy together. Thank you

I am getting somewhere, but it still allows an invalid date to be entered, for instance:

Help, please. :slight_smile:

 $pattern = "/([0-1]{1})([0-9]{1})-([0-3]{1})([0-9]{1})-([2]{1})([0-1]{1})([0-9]{2})/";	// 2digSEP2digSEP4dig
  			    if(preg_match($pattern, $_GET['dBegin'])){;
      			    echo "valid date<br/>";
      			    echo "invalid date<br/>";


font=Courier New- /.- /.\d\d[/font]

Unknown modifier '['

:frowning: Thank you for helping though… it’s probably something I am goofing up at this point.

Could someone please post the proper pattern, and explain it in plain english.

I want the end-user to have to input a valid date in the following format:

valid meaning no 14-35-200777

I’d really appreciate it… as it’s making me nuts… getting up for a beather might help though. :expressionless:

Sorry, forgot brackets. Also ive taken out the . seperator as you don’t require them.

Try this in your $pattern

$pattern = "((0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])[-](19|20)\\d\\d)";


( (0[1-9]|1[012]) [-] (0[1-9]|[12][0-9]|3[01]) [-] (19|20)\d\d )

Front and rear bracket just enclose the expression.

(0[1-9]|1[012]) Zero followed by a One to Nine OR One followed by a Zero One or Two

[-] must be character -

(0[1-9]|[12][0-9]|3[01]) Zero followed by a One to Nine OR a One or a Two followed by a Zero to Nine OR a Three followed by a Zero or One

[-] must be character -

(19|20)\d\d ) Nineteen OR Twenty followed by two decimal numbers