aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes isValidDateTime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "isValidDateTime" Watch "isValidDateTime" New topic
Author

isValidDateTime

Namnai Kidorkar
Greenhorn

Joined: Jul 02, 2005
Posts: 25
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.
Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
hope this helps !!

Date and Calendar


SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
Namnai Kidorkar
Greenhorn

Joined: Jul 02, 2005
Posts: 25
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.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Namnai Kidorkar,

Are the seconds optional?

Eric
Namnai Kidorkar
Greenhorn

Joined: Jul 02, 2005
Posts: 25
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42932
    
  68

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
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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 ]
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
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...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jul 02, 2005
Posts: 25
it works. thanks a LOT erik.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: isValidDateTime