Click to See Complete Forum and Search --> : How to pattern match dd-MON-yyyy
bostonnole
11-10-2003, 08:45 AM
Sorry, but I am a novice with JavaScript. I need to know the syntax for doing a pattern match of a date field that will be in the format: dd-MON-yyyy, where dd is the date, MON is the three character abreviation of the month and yyyy is the fully 4 digit year.
I've bungled my way into this so far but it does not work at all:
var regDate3 = /(0?[1-9]|[1-2]\d)|3(0|1)-(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-d{4}/;
Please, any help would be greatly appreciated.
bostonnole
11-10-2003, 09:08 AM
bump
AdamGundry
11-10-2003, 10:13 AM
Try this:
var regDate3 = /\d{2}-(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-\d{4}/;
Adam
bostonnole
11-10-2003, 10:23 AM
Thanks Adam, that was exactly what I was looking for!!!
olerag
11-10-2003, 10:54 AM
Adam,
Sorry but this one escapes me. How is this pseudo-code
used to check, lets say, a <input type="text"> object if the
value entered is, oh, 04-JUL-1776??
bostonnole
11-10-2003, 11:24 AM
This is what I wound up with:
<INPUT TYPE='TEXT' NAME='txtDate' onChange='checkDateValues(this);'>
<SCRIPT>
function checkDateValues(obj) {
var regDate = /^ *((0?[1-9]|[1-2]\d)|3(0|1)) *\-(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-\d{4}/;
L_BadDate = "This parameter is of type \"Date\" and should be in the format \"dd-MON-yyyy\" where \"dd\" is the number of days into the given month, \"MON\" is the month (e.g. January = JAN), and \"yyyy\" is the four digit year.";
if (obj.value != "") {
value = obj.value;
if ( ! regDate.test ( value ) )
{
// type is a Date
alert ( L_BadDate );
obj.focus();
obj.select();
return false;
}
}
}
</SCRIPT>
olerag
11-10-2003, 12:08 PM
Thanx,
Totally ignorant on reg exp notation and I haven't seen
the "test()" function before.
Have to check this stuff out.