javascript常用函数(收集中)
//trim()函数
function Trim(strVal)
{
var tempStr ;
tempStr = strVal.replace(/(^\s*)|(\s*$)/g, '');
return tempStr;
}
//验证数字、字母
function checkIsCode(str)
{
var iStr;
var aStr;
aStr = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
iStr = Trim(str);
for(i=0;i<iStr.length;i++)
{
if(aStr.indexOf(iStr.substr(i,1))<0)
{
return false;
}
}
return true;
}
function GetDaysOfMonth(year,month)
{
var iYear = parseInt(year,10);
//是否是闰年
var bRN = false;
if ((iYear%4==0 && iYear%100!=0) || iYear%400==0)
{
bRN = true;
}
var iMonth = parseInt(month,10);
switch(iMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
if (bRN)
return 29;
else
return 28;
default:
return 30;
}
}

function valid_email(email)
{
if(trim(email) == "")
return false;
if(email.match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9]+)+$") == null)
return false;
return true;
}
function valid_numeric(number)
{
if (number.match(/\D/) != null)
return false;
else
return true;
}
function trim(strIn)
{
var strOut = "";
if (strIn)
strOut = strIn.replace(/^\s*/,'').replace(/\s*$/, '');
return strOut;
}
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利
This posting is provided "AS IS" with no warranties, and confers no rights.
This posting is provided "AS IS" with no warranties, and confers no rights.


浙公网安备 33010602011771号