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.
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
posted
0
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: 15357
6
posted
0
Namnai Kidorkar,
The script I posted should work for you. If you are validating a form field all you need to do is:
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.