17个javascript自定义函数库

来源:asp之家 时间:2008-02-26 11:49:00 

-------------- 函数检索 --------------
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;
else
return false;
}
else
return false;
}//~~~
/**

校验整型最大值
*str:要校验的串。 val:比较的值
*
*返回值:
*如果为空,定义校验通过, 返回true
*如果满足条件,小于等于给定值,校验通过,返回true
*如果大于给定值, 返回false 参考提示信息:输入值不能大于给定值!
*/

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;
}//~~~

 

标签:函数,javascript,库
0
投稿

猜你喜欢

  • 2008年个性设计挂历参考

    2007-12-29 20:30:00
  • 指导:SQL Server无日志恢复数据库

    2009-02-20 17:07:00
  • 让验证码友好一点

    2007-10-20 13:45:00
  • 将一个图片以二进制值的形式存入Xml文件中

    2008-09-04 11:24:00
  • 使用ewebeditor可能会重复提交数据两次的解决办法

    2009-01-09 12:41:00
  • MYSQL数据库实用学习资料之常用命令集合

    2009-03-06 18:12:00
  • JavaScript 解析 Cookie 的函数

    2007-11-08 11:58:00
  • WEB2.0网页制作标准教程(4)如何调用css样式表

    2007-11-13 13:26:00
  • 数字人组件反写[asp组件开发实例4]

    2009-06-09 13:20:00
  • asp如何在页面中实现对电子信箱的访问?

    2010-06-26 12:34:00
  • Dreamweaver MX 2004新特点

    2008-02-03 11:35:00
  • 中国目前流行的网页设计风格

    2007-12-20 12:57:00
  • H1标签的定义

    2008-07-29 12:43:00
  • 高性能表现的网站(译)

    2008-08-31 20:26:00
  • 在线HTML编辑器原理(eweb原理)

    2009-01-08 12:25:00
  • asp如何将产生的密码记录并发送给用户?

    2009-11-26 20:50:00
  • 使用 JavaScript 获取本地盘符

    2010-01-12 13:49:00
  • MySQL 5.0.16的乱码问题解决方法

    2011-12-14 18:33:24
  • 30万条数据,搜索文本字段的各种方式对比

    2010-05-02 10:17:00
  • AJAX中文乱码解决

    2009-07-03 13:43:00
  • asp之家 网络编程 m.aspxhome.com