navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
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

Search Forums
 

Advanced search
Recent Posts

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

 

javascript date verification

 
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 verification
Page: [1]
 
malky800

 

Posts: 116
Joined: 1/11/2006
Status: offline

 
javascript date verification - 7/29/2008 14:57:22   
I looked online for a javascript date verification script. After alot of work I managed to adapt it to my form and get it work. Now no matter what I type in the date field, it tells me is invalid. Even if it really is.
What is wrong with the script?
	var input = theForm.DOB.value;
	
	var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
	var returnval=false
if (!validformat.test(input.value)) {
	alert("Invalid Date Format. Please correct and submit again.")
		    theForm.DOB.focus();
    return (false);
	} 
else{   //Detailed check for valid date ranges
	var monthfield=input.value.split("/")[0]
	var dayfield=input.value.split("/")[1]
	var yearfield=input.value.split("/")[2]
	var dayobj = new Date(yearfield, monthfield-1, dayfield)
		if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)) {
		alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
		    theForm.DOB.focus();

return (false);
	}
	}
TexasWebDevelopers

 

Posts: 202
Joined: 2/22/2002
From:
Status: offline

 
RE: javascript date verification - 7/29/2008 20:11:01   
This works--
<script language="JavaScript">
<!--
function checkdate(input){
var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
var returnval=false
if (!validformat.test(input.value))
alert("Invalid Date Format. Please correct and submit again.")
else{ //Detailed check for valid date ranges
var monthfield=input.value.split("/")[0]
var dayfield=input.value.split("/")[1]
var yearfield=input.value.split("/")[2]
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
else
returnval=true
}
if (returnval==false) input.select()
return returnval
}
//-->
</script>
<form action="" name="theForm" id="theForm" onSubmit="return checkdate(this.DOB)">
<input name="DOB" type="text">
<input name="" type="submit">
</form> 

(in reply to malky800)
malky800

 

Posts: 116
Joined: 1/11/2006
Status: offline

 
RE: javascript date verification - 7/30/2008 11:52:21   
Thank you for your answer, except, your script only validates that one date field from the form. My validation script is running along a long string of other validations from a long form. How can I get it to return false in the middle of the script instead of getting just a return on one function?

(in reply to TexasWebDevelopers)
Page:   [1]

All Forums >> Web Development >> General Web Development >> javascript date verification
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