IT Community - Software Programming, Web Development and Technical Support

Check that a string contains a date.

This is a discussion on Check that a string contains a date. within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all... Can anyone tell me how can i check that a string contains a date. Thanks in advance......


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 (permalink)  
Old 03-10-2008, 01:20 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Check that a string contains a date.

Hi all...


Can anyone tell me how can i check that a string contains a date.


Thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-10-2008, 01:23 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Re: Check that a string contains a date.

Hi all...



<script language="JavaScript">
function validateDate(date) {
// NaN is never equal to itself.
if (Date.parse(date) != Date.parse(date))
document.write(date + ' - Invalid date<br>');
else
document.write(date + ' - Valid date<br>');
}


validateDate('hello world');
validateDate('29 January 1999');
validateDate('February 30 2000');
validateDate('Sat 8 2000 Jan');
</script>


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-11-2008, 09:01 PM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: Check that a string contains a date.

<script language="JavaScript"><!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isDate (day,month,year) {
// checks if date passed is valid
// will accept dates in following format:
// isDate(dd,mm,ccyy), or
// isDate(dd,mm) - which defaults to the current year, or
// isDate(dd) - which defaults to the current month and year.
// Note, if passed the month must be between 1 and 12, and the
// year in ccyy format.

var today = new Date();
year = ((!year) ? y2k(today.getYear()):year);
month = ((!month) ? today.getMonth():month-1);
if (!day) return false
var test = new Date(year,month,day);
if ( (y2k(test.getYear()) == year) &&
(month == test.getMonth()) &&
(day == test.getDate()) )
return true;
else
return false
}

if (isDate(31,2,1997))
document.write("Valid");
else
document.write("Invalid");
//--></script>
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if a date is valid. itbarota HTML, CSS and Javascript Coding Techniques 3 04-10-2008 04:04 PM
Convert String to Date: new Date(string) oxygen Flash Actionscript Programming 3 03-07-2008 09:24 PM
Convert a date in milliseconds back to a date string itbarota HTML, CSS and Javascript Coding Techniques 2 03-03-2008 09:03 PM
How do you check if a date is valid? itbarota HTML, CSS and Javascript Coding Techniques 4 12-19-2007 12:06 AM
How can I compare a date in a string with todays date? itbarota HTML, CSS and Javascript Coding Techniques 2 12-18-2007 11:02 PM


All times are GMT -7. The time now is 11:33 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0