Page 1 of 1

date / time regex

Posted: Mon Jan 29, 2007 7:32 pm
by trent2800
I cant see why this wont work:

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

I am attempting to make sure that the date/time is formatted this way:

mm/dd/yyyy hh:mm

Any help would be most appreciated.

Posted: Mon Jan 29, 2007 7:38 pm
by Kieran Huggins
in php or javascript?

Posted: Mon Jan 29, 2007 7:47 pm
by trent2800
... (lowers head) ... vbscript...

Posted: Mon Jan 29, 2007 8:08 pm
by Kieran Huggins
... (beats trent2800 with a rank kipper) ... ;-)

Sorry trent - you might find vbscript knowledge a little thin around here, I know I never did anything of consequence in it :-(

It works in javascript:

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta name="Author" content="Kieran Huggins - http://kieran.ca" />
	<link rel="stylesheet" href="" media="screen" />
	<style type="text/css">input{width: 400px;}</style>
	<script type="text/javascript">
		function validate(input){
			var rx = document.getElementById('regex');
			var dt = document.getElementById('date');			
			var op = document.getElementById('output');
			if(dt.value.match(rx.value)){
				op.value='match';
			}else{
				op.value='';
			}
		}
	</script>
</head>
<body onload="validate()">
  <input id="date" type="text" value="12/08/1979 15:36" onkeyup="validate()"/><br/>
  <input id="regex" type="text" value="(0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])/(19|20)\d\d [012]\d:[0-5]\d" onkeyup="validate()"/><br/>
  <input id="output" type="text" style="color: green;"/>
</body>
</html>
Anyone else?

Posted: Mon Jan 29, 2007 11:28 pm
by trent2800
couldn't stand it one more second... I converted the entire thing over to javascript. ... Javascript, I'll never leave you again, old friend ...

P.S. Works great, thanks a lot.

Posted: Tue Jan 30, 2007 12:26 am
by Kieran Huggins
welcome home ;-)