日期:2013-01-07  浏览次数:20994 次

//opt1 小数     opt2   负数
//当opt2为1时检查num是否是负数
//当opt1为1时检查num是否是小数
//返回1是正确的,0是错误的
function chknbr(num,opt1,opt2)
{
    var i=num.length;
    var staus;
//staus用于记录.的个数
    status=0;
    if ((opt2!=1) && (num.charAt(0)=='-'))
    {
        //alert("You have enter a invalid number.");
        return 0;
    
    }
//当最后一位为.时出错
    if (num.charAt(i-1)=='.')
    {
        //alert("You have enter a invalid number.");
        return 0;
    }

    for (j=0;j<i;j++)
    {
        if (num.charAt(j)=='.')
        {
            status++;
        }
        if (status>1)
        {
        //alert("You have enter a invalid number.");
        return 0;        
        }
        if (num.charAt(j)<'0' || num.charAt(j)>'9' )
        {
            if (((opt1==0) || (num.charAt(j)!='.')) && (j!=0))
            {
                //alert("You have enter a invalid number.");
                return 0;
            }
        }
    }
    return 1;
}

//函数名:chkdate
//功能介绍:检查是否为日期
//参数说明:要检查的字符串
//返回值:0:不是日期  1:是日期
function chkdate(datestr)
{
    var lthdatestr
    if (datestr != "")
        lthdatestr= datestr.length ;
    else
        lthdatestr=0;
        
    var tmpy="";
    var tmpm="";
    var tmpd="";
    //var datestr;
    var status;
    status=0;
    if ( lthdatestr== 0)
        return 0

    
    for (i=0;i<lthdatestr;i++)
    {    if (datestr.charAt(i)== '-')
        {
            status++;
        }
        if (status>2)
        {
            //alert("Invalid format of date!"