megabyte214
Programmer
I am trying to validate a form field which needs to be a date in a specific format. I am new to javascript and I need a little help with the javascript synax. The regular expression does work, that I tested. I think it is a problem with how I am using the RegExp constructor. Thanks in advance for any input.
[code}
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
function validate(){
var regex = "^((31(?! (FEB|APR|JUN|SEP|NOV)))|((30|29)(?! FEB))|(29(?= FEB (((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])-(JAN|FEB|MAR|MAY|APR|JUL|JUN|AUG|OCT|SEP|NOV|DEC)-((1[6-9]|[2-9]\d)\d{2})$";
var re = new RegExp(regex);
if (document.my_form.v_Date.value.match(re)) {
alert("Valid Date");
}
else
{
alert("Invalid Date");
}
}
</SCRIPT>
</HEAD>
<BODY>
<form METHOD="get" ACTION="" NAME="my_form" onsubmit="return validate()">
<center><TABLE class="form">
<TR>
<TD colspan="2">Date (DD-MON-YYYY):
<INPUT TYPE="text" NAME="v_Date" SIZE="11" >
</TD>
</TR>
<TR>
<TD colspan="2"><center><INPUT TYPE="submit" VALUE=" Submit "></center>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
[/code]
[code}
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaScript">
function validate(){
var regex = "^((31(?! (FEB|APR|JUN|SEP|NOV)))|((30|29)(?! FEB))|(29(?= FEB (((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\d|2[0-8])-(JAN|FEB|MAR|MAY|APR|JUL|JUN|AUG|OCT|SEP|NOV|DEC)-((1[6-9]|[2-9]\d)\d{2})$";
var re = new RegExp(regex);
if (document.my_form.v_Date.value.match(re)) {
alert("Valid Date");
}
else
{
alert("Invalid Date");
}
}
</SCRIPT>
</HEAD>
<BODY>
<form METHOD="get" ACTION="" NAME="my_form" onsubmit="return validate()">
<center><TABLE class="form">
<TR>
<TD colspan="2">Date (DD-MON-YYYY):
<INPUT TYPE="text" NAME="v_Date" SIZE="11" >
</TD>
</TR>
<TR>
<TD colspan="2"><center><INPUT TYPE="submit" VALUE=" Submit "></center>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
[/code]