TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-11-2009, 01:20 PM   #1 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default Date parsing issue

I have this issue where I MUST use JavaScript to parse all dates on the page and reformat them, now I figured using the match method and replace the found results with the reformatted dates would be fine but it stands that my Regex is failing or I'm implementing the method incorrectly.


javascript Code:
var Matches = document.body.innerHTML.match(/\d{4}(\-)\d{2}(\-)\d{2}/);
alert(Matches); //Null
 

Anyone wants to have a looksie and see if possibly I'm just missing the glaringly obvious?

EDIT: Well than...Don't I feel stupid, I was missing the global search 'g' flag...I'll leave this here for anyone's future needs
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 08-11-2009, 01:29 PM   #2 (permalink)
The Wanderer
 
Join Date: Aug 2009
Location: Pretoria, South Africa
Posts: 11
Thanks: 0
devnull is on a distinguished road
Default

You are executing the code before the document has finished loading, thus it's not picking any of the dates up.

javascript Code:
<body>
2009-08-22
<script>
var Matches = document.body.innerHTML.match(/\d{4}(\-)\d{2}(\-)\d{2}/);
alert(Matches); //Null
</script>
</body>

Or you could just tell the javascript to execute once the document has finished loading.

javascript Code:
<head>
<script>
window.onload = function()
{
    var Matches = document.body.innerHTML.match(/\d{4}(\-)\d{2}(\-)\d{2}/);
    alert(Matches); //Null
}
</script>
</head>
<body>
2009-08-22
</body>
__________________
~ Work is love made visible ~

Flexible Programming Tips & Tricks

Last edited by devnull : 08-11-2009 at 01:35 PM. Reason: Highlighted :P
Send a message via Skype™ to devnull
devnull is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
PHP Access Date problems. mtsang Absolute Beginners 4 06-27-2009 04:59 PM
peculiar date issue allworknoplay Absolute Beginners 8 06-09-2009 08:06 AM
help me figure out this date thing sarmenhb Absolute Beginners 5 09-15-2008 04:20 PM
Need more ideas for date and time class Wildhoney General 2 01-18-2008 02:22 PM
converting to mysql date format harryhood Absolute Beginners 1 08-21-2005 03:57 AM


All times are GMT. The time now is 02:33 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design