PDA

View Full Version : Short Date Validation


Basscyst
07-12-2004, 01:26 AM
This is my first little script using RegEx. I felt so proud I thought I would post it. It will allow for any delimiter between Month Day & Year. I checked the validity of the actual numbers entered in, in the same fashion as a similar script posted by Whammy (Thank you Whammy, good idea!).


<script type="text/javascript">

function dateValid(frm)
{

var str=frm.replace(/\W/g, "/");
var cut=str.split('/');
var dt=new Date(str);
var mt=dt.getMonth()+1;

if(cut[0]!=mt)
{
alert("Please Enter A Valid Date");
}
else
{

chk2=str.search(/^\d{1,2}\/\d{1,2}\/\d{4}/)

if(chk2==-1)
{
alert("Please Provide A Valid Date!");
}
else
{
alert("The Date Is Right!")
}
}
}
</script>


Basscyst