IT Community - Software Programming, Web Development and Technical Support

Validate a date to be in the format dd/mm/yyyy

This is a discussion on Validate a date to be in the format dd/mm/yyyy within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all... Can anyone tell me how can i validate a date to be in the format dd/mm/yyyy. ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 02-25-2008, 08:19 PM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 542
itbarota is on a distinguished road
Default Validate a date to be in the format dd/mm/yyyy

Hi all...


Can anyone tell me how can i validate a date to be in the format dd/mm/yyyy.



Thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 02-25-2008, 08:21 PM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 235
Pvinothkumar is on a distinguished road
Default Re: Validate a date to be in the format dd/mm/yyyy

Hi all...


<SCRIPT LANGUAGE="JavaScript">
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

var reason = '';

function isValidDate (myDate,sep) {
// checks if date passed is in valid dd/mm/yyyy format

if (myDate.length == 10) {
if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep) {
var date = myDate.substring(0,2);
var month = myDate.substring(3,5);
var year = myDate.substring(6,10);

var test = new Date(year,month-1,date);

if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
reason = '';
return true;
}
else {
reason = 'valid format but an invalid date';
return false;
}
}
else {
reason = 'invalid spearators';
return false;
}
}
else {
reason = 'invalid length';
return false;
}
}

function tellMeIfInvalid(myDate) {
if (isValidDate(myDate,'/'))
document.write(myDate + ' = valid date<BR>');
else
document.write(myDate + ' = ' + reason + '<BR>');
}

tellMeIfInvalid('21/02/1999');
tellMeIfInvalid('2190291999');
tellMeIfInvalid('2/02/1999');
tellMeIfInvalid('21/2/1999');
tellMeIfInvalid('21/02/199');
tellMeIfInvalid('32/02/1999');
tellMeIfInvalid('21/02/1999');
</SCRIPT>


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Show all the dates between two dates in YYYY-MM-DD format itbarota HTML, CSS and Javascript Coding Techniques 2 03-11-2008 08:05 PM
Date format yymmdd itbarota HTML, CSS and Javascript Coding Techniques 2 03-03-2008 08:07 PM
How can I show the documents last modified date in the format: month, date, year, tim Pvinothkumar HTML, CSS and Javascript Coding Techniques 3 12-28-2007 04:58 AM
How do I format the Last-Modified date with javascript? Pvinothkumar HTML, CSS and Javascript Coding Techniques 1 10-12-2007 10:17 PM
How to convert a date to a globally accepted date format, in DOT NET 2005? Archer C# Programming 1 07-25-2007 02:21 AM


All times are GMT -7. The time now is 04:53 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0