今天天气好晴朗处处好风光,好天气好开始,图老师又来和大家分享啦。下面给大家推荐javascript函数库,希望大家看完后也有个好心情,快快行动吧!
【 tulaoshi.com - Web开发 】
/*
-------------- 函数检索 --------------
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
sp; 参考提示信息:输入值不能大于给定值!
*/
function checkIntegerMaxValue(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;
else
return false;
}
else
return false;
}//~~~
/**
*校验整型是否为非负数
*str:要校验的串。
*
*返回值:
*如果为空,定义校验通过,返回true
*如果非负数, 返回true
*如果是负数, 返回false 参考提示信息:输入值不能是负数!
*/
function isNotNegativeInteger(str)
{
//如果为空,则通过校验
if(str == "")
return true;
if(checkIsInteger(str) == true)
{
if(parseInt(str,10) 0)
return false;
else
return true;
}
else
return false;
}//~~~
/*--------------------------------- Integer --------------------------------------*/
/********************************** Double ****************************************/
/**
*校验字符串是否为浮点型
*返回值:
*如果为空,定义校验通过, 返回true
*如果字串为浮点型,校验通过, 返回true
*如果校验不通过, 返回false 参考提示信息:输入域不是合法的浮点数!
*/
function checkIsDouble(str)
{
//如果为空,则通过校验
if(str == "")
return true;
//如果是整数,则校验整数的有效性
if(str.indexOf(".") == -1)
{
if(checkIsInteger(str) == true)
return true;
else
&nbs
来源:http://www.tulaoshi.com/n/20160219/1604283.html
看过《javascript函数库》的人还看了以下文章 更多>>