I am trying to validate if an entry on a form is a date.
I have adapted code I found here
http://www.codingforums.com/archive/index.php/t-14325 as below but I can't
seem the get the results that I am expecting.
Can anyone help please
TIA
Steve
PS I'm new to javascript
-------------------------------------------------
<html>
<script TYPE = "text/javascript">
function isDate(sDate) {
var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
if (re.test(sDate) ) {
var dArr = sDate.split("/");
var d = new Date(sDate);
return d.getMonth() + 1 == dArr[0] && d.getDate() == dArr[1] &&
d.getFullYear() == dArr[2];
alert("A Date")
}
else {
alert("Not a Date")
return false;
}
}
</script>
<body>
Date: <input name=Date size=10 onBlur="JavaScr ipt:isDate();">
NEXT: <input name=NEXT size=10>
</body>
</html>
I have adapted code I found here
http://www.codingforums.com/archive/index.php/t-14325 as below but I can't
seem the get the results that I am expecting.
Can anyone help please
TIA
Steve
PS I'm new to javascript
-------------------------------------------------
<html>
<script TYPE = "text/javascript">
function isDate(sDate) {
var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
if (re.test(sDate) ) {
var dArr = sDate.split("/");
var d = new Date(sDate);
return d.getMonth() + 1 == dArr[0] && d.getDate() == dArr[1] &&
d.getFullYear() == dArr[2];
alert("A Date")
}
else {
alert("Not a Date")
return false;
}
}
</script>
<body>
Date: <input name=Date size=10 onBlur="JavaScr ipt:isDate();">
NEXT: <input name=NEXT size=10>
</body>
</html>
Comment