I have wrote this and my teacher says my function is correct but when I asked her why it does not work instead of telling my what I did wrong she offered to let me do this with out using regular expression. I would like to know what I have done wrong. this is what the assignment was
Create a Web page that contains a text box in which users can enter a date. Also include a button that executes the test() method to validate the date against a regular expression. Write a regular expres-sion pattern that allows users to enter a one- or two- digit month, one- or two- digit date, and two- or four- digit year. Also, allow users to separate the month, date, and year by using either dashes or for-ward slashes. Users should be able to enter any of the following date formats: 11- 2- 07, 1- 25- 2007, or 01/ 25/ 2007.
This is what I have
[code=html]
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>validate Date</title>
<script>
function validateDate() {
var datePattern = /^d{1,2}[/-]d{1,2}[/-]d{2,4}$/;
var date = document.getElementById(“date”).value;
document.writeln(date);
if (datePattern.test(date))
document.write(“<b>VALID DATE</b>”);
else
document.write(“<b>INVALID DATE</b>”);
}
</script>
</head>
<body>
<form name=”date”>
Date: <input Type=”text” name=”value” size=”18″ /><br />
<input type=”button” value=”test” onclick=”validateDate()” />
</form>
</body>
</html>