dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersUltimaterengan
Sameer Sayani
sabareesh reddy
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » TypeScript » Scripting Languages » Javascript

Javascript code for validating date format


Posted Date:     Category: Javascript    
Author: Member Level: Gold    Points: 10



 


//Javascript code for validating date format

function isValidDateFormat(date)
{

var date = document.getElementById(date).value;

var m = date.substring(3,5);
var d = date.substring(0,2);
var y = date.substring(6,10);

if((date.length > 10)
||((date.charAt(2)!="-")
&&(date.charAt(2)!="/"))
||((date.charAt(5)!="-")
&&(date.charAt(5)!="/"))
||(d>31) ||(m>12) ||(y<1900))
{

return false;

}
else
{

var m = date.substring(3,5);
var d = date.substring(0,2);
var y = date.substring(6,10);

if (d==0 ||m==0 ||y==0 )
{

return false;

}

if(m==01||m==03||m==05||m==07||m==08||m==10||m==12)
{

var dmax = 31;

}
else if (m==04||m==06||m==09||m==11)
{

var dmax = 30;

}
else
{

if((y%400==0) || (y%400==0 && y%100!=0))
{

dmax = 29;

}

else dmax = 28;

}

if (d>dmax)

return false;

}

return true;

}





Did you like this resource? Share it with your friends and show your love!


Responses to "Javascript code for validating date format"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Javascript code for comparing two dates
    Previous Resource: JavaScript code for checking days difference with two dates
    Return to Resources
    Post New Resource
    Category: Javascript


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Javascript code for validating date format  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.