Out of curiosity, is there anyone out there that would know of a way to simplify this process. I am writing a regular expression for a date validator that only accepts the mm.dd.yyyy mm/dd/yyyy, or mm-dd-yyyy formats. This way works, I think, but it seems really drawn out.
function c(x, y)
{
//check that there is a date and in right order
if ((x==1) || (x==3))
{
if( y == "")
{alert("You have not entered a date");
return false;
}
var string = document.getElementById('date');
var w = string.value.search(/^(\d{2})([ ./-]{1})(\d{2})\2(\d{4})$/);
if (w != 0)
{
alert("Bad Date pattern match please redo");
return false;
}
var patt=/\d{2}/
var result=patt.exec(string.value);
if(result > 12)
{
alert("Please redo Date(Month)");
return false;
}
patt2=/([ ./-])\d{2}\1/
result=patt2.exec(string.value);
result=patt.exec(result);
if(result > 31)
{
alert("Please redo Date(Days)");
return false;
}
patt=/([ ./-])\d{4}/
result=patt.exec(string.value);
patt2=/\d{4}/
result=patt2.exec(result);
if(result > 2011)
{
alert("Please redo Date(Years)");
return false;
}
}