Share it

Bookmark and Share

Translate

Thursday, July 3, 2014

1 No of days in a month validation


        function caldays(m,y)
        {
            if (m == 01 || m == 03 || m == 05 || m == 07 || m == 08 || m == 10 || m == 12)
            {
                return 31;             
            }
            else if (m == 04 || m == 06 || m == 09 || m == 11)
            {
                return 30;       
            }
            else
            {   
                if ((y % 4 == 0) || (y % 400 == 0 && y % 100 != 0))
                {   
                    return 29;         
                }
                else
                {
                    return 28;             
                }
            }   
        }


        /****No of days in a month validation*****/
        var sYear = jQuery("#yy-from").val();
        var sMonth = jQuery("#mm-from").val();
        var sDate = jQuery("#dd-from").val();
       
       
        var sMaxDate = caldays(sMonth,sYear);
        if(sDate > sMaxDate) {
           
            jQuery(".date-from-li .select2-choice").addClass('error');
        }
       
       
        var eYear = jQuery("#yy-to").val();
        var eMonth = jQuery("#mm-to").val();
        var eDate = jQuery("#dd-to").val();
       
        var eMaxDate = caldays(sMonth,sYear);
        if(eDate > eMaxDate) {
        jQuery(".date-to-li .select2-choice").addClass('error');
        }
        /*******end******/

1 comments:

  1. The validator worked for my very well for a long time, but suddenly I've found an error. I started to use custom validation function and it works nice, but the error message is shown only if there are some other errors in the form. When there is only one error, found by this function, - the error message is not shown, the web script stops working. Below is the validation part of the script: Do you have any thoughts - what is wrong ?


    function howLong()
    {
    var frm = document.forms["phpgen1"];
    if ((frm.toh.value - frm.fromh.value) > 3) {
    sfm_show_error_msg('Too long lecture!');
    return false;
    } else {
    return true;
    }
    }
    var frmvalidator = new Validator("phpgen1");
    frmvalidator.addValidation("lecnam","req","Please insert lecturer");
    frmvalidator.addValidation("lecnam","maxlen=20","Lecturer name is too long");
    frmvalidator.addValidation("lecnam","minlen=4","Lecturer name is too short");
    frmvalidator.addValidation("c_numb","req","Please select course");
    frmvalidator.addValidation("c_numb","dontselect=000000","Please select course");
    frmvalidator.addValidation("typ","dontselect=0","Select type of studies");
    frmvalidator.setAddnlValidationFunction(howLong);
    frmvalidator.EnableFocusOnError(false);
    frmvalidator.EnableOnPageErrorDisplaySingleBox();
    frmvalidator.EnableMsgsTogether();

    ReplyDelete

Thanks for your valuable Comment

 

TechnoTipworld- Tips,Tricks,Technology Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates