常用javascript函数(一)


/*********************************************************************************
*    FUNCTION:        isBetween
*    PARAMETERS:        val        AS any value
*                    lo        AS Lower limit to check
*                    hi        AS Higher limit to check
*    CALLS:            NOTHING
*    RETURNS:        TRUE if val is between lo and hi both inclusive, otherwise false.
**********************************************************************************/
function isBetween (val, lo, hi) {
    if ((val < lo) || (val > hi)) { return(false); }
    else { return(true); }
}

/*********************************************************************************
*    FUNCTION:        isDate checks a valid date
*    PARAMETERS:        theStr        AS String
*    CALLS:            isBetween, isInt
*    RETURNS:        TRUE if theStr is a valid date otherwise false.
**********************************************************************************/
function isDate (theStr) {
    var the1st = theStr.indexOf('-');
    var the2nd = theStr.lastIndexOf('-');
   
    if (the1st == the2nd) { return(false); }
    else {
        var y = theStr.substring(0,the1st);
        var m = theStr.substring(the1st+1,the2nd);
        var d = theStr.substring(the2nd+1,theStr.length);
        var maxDays = 31;
       
        if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
            return(false); }
        else if (y.length < 4) { return(false); }
        else if (!isBetween (m, 1, 12)) { return(false); }
        else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
        else if (m==2) {
            if (y % 4 > 0) maxDays = 28;
            else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
               else maxDays = 29;
        }
        if (isBetween(d, 1, maxDays) == false) { return(false); }
        else { return(true); }
    }
}
/*********************************************************************************
*    FUNCTION:        isEuDate checks a valid date in British format
*    PARAMETERS:        theStr        AS String
*    CALLS:            isBetween, isInt
*    RETURNS:        TRUE if theStr is a valid date otherwise false.
**********************************************************************************/
function isEuDate (theStr) {
    if (isBetween(theStr.length, 8, 10) == false) { return(false); }
    else {
        var the1st = theStr.indexOf('/');
        var the2nd = theStr.lastIndexOf('/');
       
        if (the1st == the2nd) { return(false); }
        else {
            var m = theStr.substring(the1st+1,the2nd);
            var d = theStr.substring(0,the1st);
            var y = theStr.substring(the2nd+1,theStr.length);
            var maxDays = 31;

            if (isInt(m)==false || isInt(d)==false || isInt(y)==false) {
                return(false); }
            else if (y.length < 4) { return(false); }
            else if (isBetween (m, 1, 12) == false) { return(false); }
            else if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
            else if (m==2) {
                if (y % 4 > 0) maxDays = 28;
                else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
                else maxDays = 29;
            }
           
            if (isBetween(d, 1, maxDays) == false) { return(false); }
            else { return(true); }
        }
    }
   
}
/********************************************************************************
*   FUNCTION:       Compare Date! Which is the latest!
*   PARAMETERS:     lessDate,moreDate AS String
*   CALLS:          isDate,isB

本文作者:



相关阅读:
硬盘“逻辑锁”的解决办法
linux下find查找命令用法
利用sql的limit属性对mysql数据库
整合Discuz用户登陆代码
silverlight2.0Beta版TextBox输入中文解决方法
javascript contains和compareDocumentPosition 方法来确定是否HTML节点间的关系
ASP3.0高级编程(一)
DEDECMS网站系统目录权限设置教程
11款新鲜的jQuery插件[附所有demo下载]
PHP的可变变量名的使用方法分享
网上提供的最简便的MySql数据库备份的方法
MySQL存储程序、函数以及复制的相关问题
英文首字母全大写的js实现脚本
Oracle并发连接数的设置
快速导航

Copyright © 2016 phpStudy | 皖ICP备18014864号-4