OutFront Forums
     Home    Register     Search      Help      Login    

Follow Us
On Facebook
On Twitter
RSS
Via Email

Recent Posts
Todays Posts
Most Active posts
Posts since last visit
My Recent Posts
Mark posts read

Sponsors
Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.
Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.
Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

 

Javascript date validation

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> Javascript date validation
Page: [1]
 
MikeO

 

Posts: 16
From: near Geneva France
Status: offline

 
Javascript date validation - 5/2/2000 16:01:00   
Not knowing anything about curly brackets and semi-colons, I spent several days developing this date validation. If it's any good, then please, please somebody else make use of it.

This is a FrontPage 2000 .asp page which uses includes the following features :
1. A valid date must be entered.
2. The date entered must be the same as or later than the server date.
3. A date must be entered.
4. The date format used is “dd/mm/yyyy”, but this can be easily modified.
5. If the comparison with the server date is not required, then this test can be removed.
6. The JavaScript function should work for any number of date fields on one or more forms.

Explanations of the script are italic.

<i>This VB script sets up the server date</i>

<%
'Set current date
aDate = now()
%>

<head>

<i>There are no changes required to this JavaScript function unless the date format is to be changed or the comparison with server date removed.</i>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

function checkdate(dtform,dtfld) {
var err = 0
var dtstr = dtfld.value
var valid = "0123456789/"
var temp;
for (var i=0; i< dtstr.length; i++) {
temp = "" + dtstr.substring(i, i+1);
if (valid.indexOf(temp) == "-1") err = 1;
}
if (dtstr.length != 10) err=1

<i>If the date format is “mm/dd/yy” then change (0, 2) in the next line to (3, 5). It’s a good idea to change the day comment to month as well !</i>

b = dtstr.substring(0, 2) // day
c = dtstr.substring(2, 3)// '/'

<i>If the date format is “mm/dd/yy” then change (3, 5) in the next line to (0, 2).</i>

d = dtstr.substring(3, 5) // month
e = dtstr.substring(5, 6)// '/'
f = dtstr.substring(6, 10) // year
if (b<1 | | b>31) err = 1
if (c != '/') err = 1
if (d<1 | | d>12) err = 1
if (e != '/') err = 1

<i>The next line contains the valid years,/I>

if (f<1900 | | f>2099) err = 1
if (d==4 | | d==6 | | d==9 | | d==11){
if (b==31) err=1
}
if (d==2){
var g=parseInt(f/4)
if (isNaN(g)) {
err=1
}
if (b>29) err=1
if (b==29 && ((f/4)!=parseInt(f/4))) err=1
}
var bb = dtform.Dy.value;
var dd = dtform.Mn.value;
var ff = dtform.Yr.value;
var sDate = new Date(ff,dd,bb);
var iDate = new Date(f,d,b);

<i>Test date is correctly formatted</i>

if (err==1) {
alert('The date must be entered in dd/mm/yyyy format.\nThe date will be unchanged.');
dtfld.focus();
dtfld.select();
return false;

<i>Test input date on of after server date. Delete the next 7 lines if not required.</i>

}else if (iDate < sDate) {
alert('The date must be on or after today.\n"' + dtstr + '" is in the past.');
dtfld.focus();
dtfld.select();
return false;

}else {
return true;
}
}

// End -->

</script>

<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>

<body>

<form method="POST" onsubmit="return FrontPage_Form1_Validator(this)" name="FrontPage_Form1" action="--WEBBOT-SELF--">
<table border="0" width="504">
<tr>
<td width="153"><b>Enter Date</b></td>
<td width="90">

<i>Use FP2000 field validation to ensure a date is entered </i>

<!--webbot bot="Validation"
s-display-name="Date" b-value-required="TRUE"
i-minimum-length="10" i-maximum-length="10" -->
<input type="text" name="inpDate" size="11" tabindex="1"

<i>Change “inpDate” in the next line to the name specified in the line above.<i/>

onchange="return checkdate(this.form,this.form.inpDate)" maxlength="10"></td>
<td width="264"><font size="1">Enter a date in "dd/mm/yyyy"
format.</font></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="B1"></p>
<input type="hidden" name="Dy" value="<%=Day(aDate)%>">
<input type="hidden" name="Mn" value="<%=Month(aDate)%>">
<input type="hidden" name="Yr" value="<%=Year(aDate)%>">
</form>

</body>


MikeO

 

Posts: 16
From: near Geneva France
Status: offline

 
RE: Javascript date validation - 5/2/2000 16:08:00   
Mutter, mutter .... how do italics and text indentations work here ? Sorry folks.

(in reply to MikeO)
Page:   [1]

All Forums >> Web Development >> General Web Development >> Javascript date validation
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts