Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expression date validation

Status
Not open for further replies.

anto2

Programmer
Apr 4, 2001
29
0
0
IE
Hello I am trying to validate a date if the format dd/mm/yy

this works fine in IE5-6

var filter=/^[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{2}$/;
if (! filter.test(inpDate))
{ alert("Please enter Date in DD/MM/YY Format !");');
return false;');
};

but I get
JavaScript Error: unterminated character class [
in Netscape

any ideas

Anthony.
 
hi anto2,

the two single quotes may be causing it, and you have some extra parentheses, and you don't need to put the forward slashes in brackets or use the {1} for them - just escape them:

var filter=/^[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{2}$/;
if (! filter.test(inpDate))
{ alert("Please enter Date in DD/MM/YY Format !");');
return false;'););
};


should be:

var filter=/^[0-9]{2}\/[0-9]{2}\/[0-9]{2}$/;
if (! filter.test(inpDate))
{ alert("Please enter Date in DD/MM/YY Format !");
return false;
} ======================================

if (!succeed) try();
-jeff
 
I got this script to work with jeff's edits in NS6 on MacOSX but not in IE5+. I don't know if your target audience will include Macs but I thought I would let you know.

jaxon
 
Thnks Jeff,

The filter works perfectly. The reason I had the extra single quotes is that I'm using Oracle Portal to build html pages and I left these in by mistake.

Anthony.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top