Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 12th, 2008, 02:28 AM
Authorized User
 
Join Date: May 2007
Location: Hyderabad, Andhra Pradesh, India.
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default regular expression for dates in dd/mm/yyyy

Hi ALL

Can anyone help me out by giving me the regular expression for six dates in dd/mm/yyyy format separated by comma.It should validate leap years too.

Something like this:

21/06/2005,24/01/2004,21/06/2003,21/05/2006,12/01/2001,23/06/2008
This will be entered in textbox and then will be validated.

  #2 (permalink)  
Old June 12th, 2008, 02:55 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I won't say this is impossible but I reckon the expression would be so unwieldy that it would be better to use procedural code.

--

Joe (Microsoft MVP - XML)
  #3 (permalink)  
Old June 12th, 2008, 07:45 AM
Authorized User
 
Join Date: May 2007
Location: Hyderabad, Andhra Pradesh, India.
Posts: 95
Thanks: 5
Thanked 0 Times in 0 Posts
Default

Hi Joe

I followed your advice and tried to validate using Javascript. Here is the code:

function fnDate()
  {
    var str = document.getElementById("txtLeaveDt").value
    var SplitDate = str.split(",");
    for(i=0;i<SplitDate.length;i++)
      {
          if(!(mydate(SplitDate[i]))
          //alert("Incorrect format");
          return false;
      }
        return true;
  }

mydate is a function to validate date in dd/mm/yyyy format, i m calling in the If condition. But i am getting error in the If condition. Did syntactically somewhere i went wrong?

-- Abhishek

  #4 (permalink)  
Old June 12th, 2008, 08:43 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Code:
if (!mydate(SplitDate[i]))

--

Joe (Microsoft MVP - XML)


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert dd/MM/yyyy to MM/dd/yyyy Rg2005 VB.NET 2002/2003 Basics 2 November 7th, 2008 06:42 PM
Date dd-mm-yyyy John2112 SQL Server 2000 2 March 16th, 2007 05:15 AM
mm/dd/yyyy to dd/mm/yyyy Ashleek007 Beginning PHP 2 September 27th, 2006 06:35 AM
convert "MM/dd/yyyy" to "dd/MM/yyyy" xin56 General .NET 4 March 28th, 2005 05:33 AM
Date formats... dd/mm/yyyy SeanW Classic ASP Databases 3 June 14th, 2004 12:34 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.