C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Allow valid Date in Textbox


Posted Date: 22 Dec 2007    Resource Type: Code Snippets    Category: Javascript

Posted By: KVGaneshBabu       Member Level: Diamond
Rating:     Points: 10



This javascript function Allow valid Date in Textbox


function validate_date(a)
{
var err=0;
var psj=0;
if (a.length != 10)
{
err=1
alert("Date value is not complete")
return 0
}
b = a.substring(3, 5)// month
c = a.substring(2, 3)// '/'
d = a.substring(0, 2)// day
e = a.substring(5, 6)// '/'
f = a.substring(6, 10)// year

if (b<1 || b>12 || isNaN(b)==true)
{
alert("Invalid month "+b)
return 0
err = 1
}

if (isNaN(d)==true)
{
alert("Invalid Day "+d)
return 0
err = 1
}

if (isNaN(f)==true)
{
alert("Invalid Year "+f)
return 0
err = 1
}
if (c != '/') err = 1
if (d<1 || d>31) err = 1
if (e != '/') err = 1
if (f<1935 || f>9999) err = 1

if (b==2 || b==4 || b==6 || b==9 || b==11)
{
if (d==31)
{
err=1
alert("Month "+b+" doesn't have 31 days!")
return 0
}
}

if (b==2)
{
// feb
var g=parseInt(f/4)
if (isNaN(g))
{
err=1
}
if (d>29)
{
err=1
alert("February " +f+ " doesn't have " +d+ " days!");
return 0;
}
if (d==29 && ((f/4)!=parseInt(f/4)))
{
err=1
alert("February " +f+ " doesn't have " +d+ " days!");
return 0;
}

}
if (err==1)
{
alert("Invalid Date")
return 0
}
else
{
return 1
}
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Allow character for address information
Previous Resource: Creating Excel Application - JavaScript
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

internet fax

Contact Us    Privacy Policy    Terms Of Use