• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

isValidDateTime

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using someone else's code. so not sure, but seems like this "isValidDateTime()" is a build in function of javascript. Assuming it is, it is only validing time and date against "mm/dd/yyyy hh:mm[:ss]" format. is there any way to change the format to "yyyy-dd-mm hh:mm[:ss]"? or use any other function? thanks in advanced.
 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hope this helps !!

Date and Calendar
 
Namnai Kidorkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the link. actually its a user defined function. i found the function but stuck at:

var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;

don't know what this means. if someone can explain the format that would be appreciated.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Namnai Kidorkar,

Are the seconds optional?

Eric
 
Namnai Kidorkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, i believe so. but the time format is the same so i don't have to change that. i've to change the date format from mm/dd/yyyy to yyyy-mm-dd.

if u could give me the right expresion for it instead of explaining that would be ok too.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;

i've to change the date format from mm/dd/yyyy to yyyy-mm-dd.



I think the following will do the trick (but haven't tried it):
var objRegExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;

If you don't know regular expressions -and that's what this is- you should absolutely read up on them. They can make every developers live easier.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regular expressions are good, but you are not looking at leap year. I would do it this way:



Eric
[ August 22, 2005: Message edited by: Eric Pascarello ]
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eric Pascarello:
..............



I didn't know that String.prototype.isValidDate = function() is the same as function isValidDate(). Is there any pros or cons for using the format that you used above?

I really don't know that such way of method declaration exists, despite several years of experience in web development... Well, mostly server-side...
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Namnai Kidorkar,

The script I posted should work for you.
If you are validating a form field all you need to do is:

return document.FormName.ElementName.isValidDate();



Ko Ko Naing,

Using prototype in JavaScript is rather handy. It allows you to create your own methods. I think it is a lot cleaner to code like that. You can develop an oo with JavaScript by using prototypes and classes. Not to advertise, but if you were to pick up Ajax in action, we first develop the code in a straight foward linear approach, then we go back and refactor the code for an oo approach. Makes it so much easier to reuse code on every page. A lot of novices to JavaScript does not know this exists.

You can read about prototype here if you are interested: http://www.webreference.com/js/column34/index.html

A group of use on another forum started to build a large list of prototype functions. I think we are at 70+. My screen name there is A1ien51. http://webdeveloper.com/forum/showthread.php?t=61883

I have a few scripts there to convert times, calc business days, and much more.

If you want to continue talking about prototypes of oo JavaScript, start a new thread.

Eric
 
Namnai Kidorkar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it works. thanks a LOT erik.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic