tuxedo210 Posted April 12, 2006 Share Posted April 12, 2006 I don't know how to validate date input by user. I want to use a fucntion to do this.Please help ..... thanks you very much ! Link to comment Share on other sites More sharing options...
scott100 Posted April 12, 2006 Share Posted April 12, 2006 Try this page: http://www.smartwebby.com/DHTML/date_validation.aspThere are many more, just ask Google Link to comment Share on other sites More sharing options...
Webworldx Posted April 12, 2006 Share Posted April 12, 2006 I wrote my own little version as I thought that website one was a little long, and hadn't done one before. Let me know what you think: <script type='text/javascript'>/*Date ParserCreated for W3Schools by Blue*/var iDate = "31/01/1962";function check_day_month(mon,year){ var myRegMon = new RegExp("(04||06||09||11)"); if(myRegMon.exec( mon ) && RegExp.$1 != ""){ return '30'; } else if(mon == '02'){ return check_feb(year); } else { return '31'; }}function check_feb(yr){ if( (yr / 4) == Math.floor(yr / 4) ){ return '29'; } else { return '28'; }}function check_date(theDate){ var myRegEx = new RegExp(/\d{2}\/\d{2}\/\d{4}/); if(theDate.length != 10 || myRegEx.test(theDate) == false){ return 'The field must be in the correct format'; } var iSplit = theDate.split(/\//g); iSplit[2] = Math.floor(iSplit[2]); if( Math.floor(iSplit[0]) > check_day_month( iSplit[1] , iSplit[2] ) ){ return 'The number of days set was not correct for the month/year'; } return 'The date was parsed successfully';}var myResult = check_date(iDate);document.write(myResult);</script> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now