codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Home » HTML » Article

Validate Date

Article by: Kannadasan Ramiah (4/24/2003)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Summary: Validating Date entered in a text box, pure HTML page
Viewed: 47883 times Rating (9 votes): 
 2.2 out of 5
 Rate this Article  Read Comments  Post Comments

Validate Date








(Format mm/dd/yyyy or mm.dd.yyyy)











Select All Code







CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'Validate Date'
Posted by :  Archive Import (Raef Abdallah) at 18:56 on Thursday, July 24, 2003
I changed line 10 from
if (InpDate.length < 6) to
if (InpDate.length < 10).

This way entering '12/12/' for example in the text box will be an invalid date. This script is very helpful.

Thanks,

Raef
Posted by :  Archive Import (Raef Abdallah) at 19:13 on Thursday, July 24, 2003
Line 10 should be changed to
if (InpDate.length < 8).

This will make

'5/3/2003' , '05/3/2003' , '05/03/2003', etc.. valid dates.

Raef


Posted by :  Archive Import (M Danyov) at 09:08 on Tuesday, August 26, 2003
let me know if this works
Posted by :  Archive Import (Aries Jay) at 14:46 on Wednesday, September 17, 2003
this works absolutely fine..and very easy
Posted by :  difase20_1984 at 20:11 on Monday, June 13, 2005
saw some bugs

such date causes a correct output
10/10/10/1
Posted by :  Raef at 19:01 on Friday, June 24, 2005
You're right about the bug. An easy fix would be to use a regular expression. You can add the lines below after the second "else" statement. The lines are as follows:




var regExpressionPhonePrefix = /\d\d\d\d/;
if((f.date.value.length > 6 ) && (!regExpressionPhonePrefix.test(f.date.value.substring(6,f.date.value.length+1)))) // try +1 instead of -1 (isNaN(f.date.value.substring(6,f.date.value.length-1))))
{

alert("That is a year for God's Sake");
return false;
break;
}

That will accept any four digit year. That's all Folks!



Posted by :  Raef at 20:40 on Friday, June 24, 2005
Just a follow up on my previous post. Just a clean up!




var regExpressionYear = /\d\d\d\d/;
if((f.date.value.length > 6 ) && (!regExpressionYear.test(f.date.value.substring(6,f.date.value.length+1))))
{
alert("That is a year for God's Sake");
return false;
break;
}

Happy Programming!


To post comments you need to become a member. If you are already a member, please log in .

 



RELATED ARTICLES
Image Submit Button
by Jeff Anderson
You can keep your forms from slipping into mundanity by substituting the default gray submit button to a colourful graphic of your choosing.
Parent _self _blank and _top Frame Target Specifications
by Jeff Anderson
How to specify frames and how to break out of them using standard link tags.
Pre Tag
by Jeff Anderson
No need to reformat text files with line breaks and tabs if you use the pre tag
Image Rollovers
by Jeff Anderson
A bit of code to swap to different images on the page. You often see this on sites to display a rollover on the navigation buttons.
ASCII characters and their codes
by Jeff Anderson
A full list of all the ASCII characters.
In-Line Frames (IFrames)
by Jeff Anderson
Inline frames or IFrames are the ones which appear in the midst of a standard page, but actually reference a totally separate url.
Validate Date
by Kannadasan Ramiah
Validating Date entered in a text box, pure HTML page
HTML Hspace and Vspace Image Borders
by Jeff Anderson
A lesser known feature in HTML is the ability to add a blank border around images both horizontally and vertically.
Creating Navigation with Frames
by Jeff Anderson
The most popular use of frames is to allow a static navigation to stay on one part of the screen (in one frame) while the content changes in another.
The OSI Reference Model - A Clear and Concise Illustration !
by James Opiko
The OSI Reference Model - A Resource For IT Certification Candidates & Networking Professionals








Recent Forum Threads
• Significant Factors
• Perl array access
• Re: huffman encoding and decoding in C++...
• Perl One Liner: Replace {(
• Re: html including php, accessing the functions
• Something like an INI editor or a DelimitedText-Editor
• Error Deleting File or Folder
• Re: How can use ASP.NET RegularExpressionValidator for alphanumeric 10 digit input
• Re: drop-down menu selected value


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009