INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Date format

checking date format by SeAL
Posted: 19 Mar 01

Here's my FAQ back! Enjoy ...

function isLeap(year){
    if(year % 400 == 0){
        return true;
    } else if((year % 4 == 0) && (year % 100 != 0)){
        return true
    } else return false;
};
    
function days_in(month, year){
    if(month == 4 || month == 6 || month == 9 || month == 11){
        return 30;
    } else if(!isLeap(year) && month == 2){
        return 28;
    } else if(isLeap(year) && month == 2){
        return 29;
    } else return 31;
};
    
function checkDate(myItem){
    var myArrayDate, myDay, myMonth, myYear, myString, myYearDigit;
    myString = myItem.value + "";
    if (myString == "" || myString == "mm/dd/yyyy"){
            myItem.value = "mm/dd/yyyy";
            return true;
    }
    myArrayDate = myString.split("/");
    
    myDay = Math.round(parseFloat(myArrayDate[1]));
    myMonth = Math.round(parseFloat(myArrayDate[0]));
    myYear = Math.round(parseFloat(myArrayDate[2]));
    myString = myYear + "";
    myYearDigit = myString.length;
    
    if (isNaN(myDay) || isNaN(myMonth) || isNaN(myYear) || (myYear < 1) || (myDay < 1) || (myMonth < 1) || (myMonth > 12) || (myYearDigit != 4) || (myDay > days_in(myMonth, myYear))){
        alert("Please check your Date format. (mm/dd/yyyy)");
        myItem.value = "mm/dd/yyyy";
        return true;
    } else{
        return false;
    }
};


You can easilly change this script to check another date format by changing the split method

Hope this helps ...

Back to Javascript FAQ Index
Back to Javascript Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close