pinkstonm
asked on
Date Value
I have several input forms that have dates on them. I want to make sure that people input the dates properly mm/dd/yy or day month year...
Is there a routine that can do this?
Is there a routine that can do this?
ASKER
Whats the html code to invoke it?
ASKER
<INPUT NAME="ced" onmouseover="fillHelp('The expiration / renewal date of the current program contract. Input data in the following format: Day-Month-Year; (i.e. –Mar-2003)')" onmouseout="fillHelp(' ')" SIZE=15 style="font-family: Arial; font-size: 10px; color: #000080" dir="ltr">
How do I connect the script to the INPUT statement
How do I connect the script to the INPUT statement
<html>
<head>
<script type="text/javascript">
<!--
function validate(fObj)
{
var err = "";
var focusField = "";
var objRegExp = /^\d{2}\/\d{2}\/\d{2}$/; // mm/dd/yy
if(!objRegExp.test(fObj["c ed"].value )){
err += "- CED";
focusField = "ced";
}
if(err != ""){
alert("The following fields contain errors:\n\n"+ err);
fObj[focusField].focus();
return false;
}
return true;
}
// -->
</script>
<style type="text/css">
<!--
.ced{
font-family: Arial;
font-size: 10px;
color: #000080;
}
-->
</style>
</head>
<body>
<form name="form1" onsubmit="return validate(this);">
<INPUT NAME="ced" class="ced" SIZE=15 dir="ltr">
<input type="submit" name="btnSubmit" value="Submit">
</form>
</body>
</html>
<head>
<script type="text/javascript">
<!--
function validate(fObj)
{
var err = "";
var focusField = "";
var objRegExp = /^\d{2}\/\d{2}\/\d{2}$/; // mm/dd/yy
if(!objRegExp.test(fObj["c
err += "- CED";
focusField = "ced";
}
if(err != ""){
alert("The following fields contain errors:\n\n"+ err);
fObj[focusField].focus();
return false;
}
return true;
}
// -->
</script>
<style type="text/css">
<!--
.ced{
font-family: Arial;
font-size: 10px;
color: #000080;
}
-->
</style>
</head>
<body>
<form name="form1" onsubmit="return validate(this);">
<INPUT NAME="ced" class="ced" SIZE=15 dir="ltr">
<input type="submit" name="btnSubmit" value="Submit">
</form>
</body>
</html>
ASKER
Is there not a way to do date validation either onfocus or onclick?
<INPUT NAME="ced" class="ced" SIZE=15 dir="ltr" onchange="return validate(this.form);">
ASKER
I have seens screens on the internet that when you begin typing in them the force __/__/__
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function formatDate(strField){
var oLen = strField.value.length;
if(oLen == 2 || oLen == 5){strField.value += "/";}
}
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="">
Date <input type="text" name="Date" maxlength="10" size="11" onkeypress="formatDate(thi s);" />
</form>
</body>
</html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function formatDate(strField){
var oLen = strField.value.length;
if(oLen == 2 || oLen == 5){strField.value += "/";}
}
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="">
Date <input type="text" name="Date" maxlength="10" size="11" onkeypress="formatDate(thi
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<script>
function test(D){
if (/^\d{2}\/\d{2}\/\d{2}$/.t
return true
else
return false
}
alert(test("22/1/12"))
alert(test("22/10/12"))
</script>