|
|
Home » HTML » Article
|
|
| Viewed: 41193 times |
Rating (9 votes): |
|
2.2 out of 5 |
|
|
|
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 :
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. |
 |
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. |
 |
Pre Tag by Jeff Anderson
No need to reformat text files with line breaks and tabs if you use the pre tag |
 |
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 |
 |
| |