2005-10-21

javascript函数库

来源: 本站收集整理 作者:佚名 评论 0 条
 
/*

-------------- 函数检索 --------------
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)
{
//假如为空,则通过校验
共5页: 上一页 1 [2] [3] [4] [5] 下一页

(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:Xhtml第9天:第一个css布局实例  
下一篇:XHTML第5天:head区的其他设置
    评论加载中…

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号