设为首页
加入收藏
站内地图
旧版入口

javascript函数库

作者:佚名 出处:网络转载 时间:12-30 点击:

内容载入中...

/*

-------------- 函数检索 --------------
trim函数:                         trim() lTrim() rTrim()
校验字符串是否为空:                 checkIsNotEmpty(str)
校验字符串是否为整型:               checkIsInteger(str)
校验整型最小值:                    checkIntegerMinValue(str,val)
校验整型最大值:                    checkIntegerMaxValue(str,val)
校验整型是否为非负数:               isNotNegativeInteger(str)
校验字符串是否为浮点型:             checkIsDouble(str)
校验浮点型最小值:                  checkDoubleMinValue(str,val)
校验浮点型最大值:                  checkDoubleMaxValue(str,val)
校验浮点型是否为非负数:             isNotNegativeDouble(str)
校验字符串是否为日期型:             checkIsValidDate(str)
校验两个日期的先后:                checkDateEarlier(strStart,strEnd)
校验字符串是否为email型:           checkEmail(str)

校验字符串是否为中文:               checkIsChinese(str)
计算字符串的长度,一个汉字两个字符:   realLength()
校验字符串是否符合自定义正则表达式:   checkMask(str,pat)
得到文件的后缀名:                   getFilePostfix(oFile) 
-------------- 函数检索 --------------
*/

/**
* added by LxcJie 2004.6.25
* 去除多余空格函数
* trim:去除两边空格 lTrim:去除左空格 rTrim: 去除右空格
* 用法:
*     var str = "  hello ";
*     str = str.trim();
*/
String.prototype.trim = function()
{
    return this.replace(/(^[s]*)|([s]*$)/g, "");
}
String.prototype.lTrim = function()
{
    return this.replace(/(^[s]*)/g, "");
}
String.prototype.rTrim = function()
{
    return this.replace(/([s]*$)/g, "");
}
/********************************** Empty **************************************/
/**
*校验字符串是否为空
*返回值:
*如果不为空,定义校验通过,返回true
*如果为空,校验不通过,返回false               参考提示信息:输入域不能为空!
*/
function checkIsNotEmpty(str)
{
    if(str.trim() == "")
        return false;
    else
        return true;
}//~~~
/*--------------------------------- Empty --------------------------------------*/
/********************************** Integer *************************************/
/**
*校验字符串是否为整型
*返回值:
*如果为空,定义校验通过,      返回true
*如果字串全部为数字,校验通过,返回true
*如果校验不通过,              返回false     参考提示信息:输入域必须为数字!
*/
function checkIsInteger(str)
{
    //如果为空,则通过校验
    if(str == "")
        return true;
    if(/^(-?)(d+)$/.test(str))
        return true;
    else
        return false;
}//~~~
/**
*校验整型最小值
*str:要校验的串。  val:比较的值
*
*返回值:
*如果为空,定义校验通过,                返回true
*如果满足条件,大于等于给定值,校验通过,返回true
*如果小于给定值,                        返回false              参考提示信息:输入域不能小于给定值!
*/
function checkIntegerMinValue(str,val)
{
    //如果为空,则通过校验
    if(str == "")
        return true;
    if(typeof(val) != "string")
        val = val + "";
    if(checkIsInteger(str) == true)
    {
        if(parseInt(str,10)>=parseInt(val,10))
            return true;
document.getElementById('loading').style.display="none";

收藏本文:
】【打印页面】【推荐给朋友】【关闭窗口
<< 上一篇 :没有了
推荐信息