You need to implement some form validation. The quickest way is JavaScript, but it can be done on the server side as well.
First limit the number of characters that can be entered in the field with the 'maxlength' attribute of the text input, like this.
HTML Code:
<input name="dateField" id="dateField" type="text" size="12" value="write DD/MM/YY" maxlength="8" />
Next validate the entry with this JavaScript function.
Code:
function validateForm()
{
with(document.getElementById("dateValueForm"))
{
var strDate = dateField.value;
var objRegExPattern = new RegExp(/^[0-9]{2}\/[0-9]{2}\/[0-9]{2}$/);
var boolValidPattern = objRegExPattern.test(strDate);
if(boolValidPattern)
{
var objDate = new Date(strDate);
if(objDate == "Invalid Date")
{
dateField.select();
}
else
{
submit();
}
}
else
{
dateField.select();
}
}
}
What the heck is all that?
1. Get the value of the date field
2. Create a Regular Expression object that ensures the the value of the date field is only two digits, a forward slash, two more digits, another forward slash, and finally two more digits, or 11/22/33.
3. Test the value of the date field with the RegEx pattern.
4. Test the validity of the pattern test.
4a. If the we have a valid pattern...
5. Try to create a Date object from the value of the date field.
5a. If the date object is not a valid date
5aa. Return the user to the form.
5b. If the date object is a valid date
5ba. Submit the form.
4b. If the pattern is invalid
4ba. Return the user to the form.
So we end up something like this.
HTML Code:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Date Value Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function validateForm()
{
with(document.getElementById("dateValueForm"))
{
var strDate = dateField.value;
var objRegExPattern = new RegExp(/^[0-9]{2}\/[0-9]{2}\/[0-9]{2}$/);
var boolValidPattern = objRegExPattern.test(strDate);
if(boolValidPattern)
{
var objDate = new Date(strDate);
if(objDate == "Invalid Date")
{
dateField.select();
}
else
{
submit();
}
}
else
{
dateField.select();
}
}
}
</script>
</head>
<body>
<form id="dateValueForm" method="post" action="sql.php" enctype="multipart/form-data">
<input name="dateField" id="dateField" type="text" size="12" value="write DD/MM/YY" maxlength="8"/>
<input type="button" value="Go" onclick="javascript:validateForm()"/>
</form>
</body>
</html>
I hope this helps.