⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 general.js

📁 j2ee源码
💻 JS
📖 第 1 页 / 共 5 页
字号:
        var blnWrongPos;

        for (j = strString.length -1; j >= 0 ; j--)
        {
            loopcnt ++;
            if (strString.charAt(j) == ",")
            {
                cnt ++;
                if (loopcnt % 4 != 0 || j==0)
                {
                    blnWrongPos = true;
                }
            }
        }

        if (blnWrongPos) return false;
        if (strString.length == 0) return false;
        if (strString.length - cnt > digit) return false;

        //  test strString consists of valid characters listed above
        for (i = 0; i < strString.length && blnResult == true; i++)
            {
            strChar = strString.charAt(i);
            if (strValidChars.indexOf(strChar) == -1 )
            {
                blnResult = false;
            }
        }
        return blnResult;
    }

    //  check for valid numeric strings
    function IsDecPart(strString, dp)
    {
        var strValidChars = "0123456789";
        var strChar;
        var blnResult = true;

        if (strString != null && strString != "")
        {
            if (strString.length > dp) return false;

            //  test strString consists of valid characters listed above
            for (i = 0; i < strString.length && blnResult == true; i++)
                {
                strChar = strString.charAt(i);
                if (strValidChars.indexOf(strChar) == -1)
                {
                    blnResult = false;
                }
            }
        }
        else
        {
            blnResult = true;
        }
        return blnResult;
    }

    //Require chkEmpty()
    //Require addMsg()
    //Require isTxtShortMonthYearDate()
    function chkTxtShortMonthYearDate(field, fieldName)
    {
        if (chkEmpty(field, fieldName))
        {
            if (isTxtShortMonthYearDate(field.value) == false)
            {
				if (langId == 'cht')
				{
					addMsg(fieldName + '必須是日期格式(MON/YYYY)。', field);
				}
				else if (langId == 'chs')
				{
					addMsg(fieldName + '必须是日期格式(MON/YYYY)。', field);
				}
				else
				{
					addMsg(fieldName + ' should be in date format(MOM/YYYY).', field);
				}
                return false;
            }
            else
                return true;
        }
        else return false;
    }

    function isTxtShortMonthYearDate(value)
    {
        var pos1 = value.indexOf(dtCh);
        if ((pos1 == -1))
            return false;
        if (value.indexOf(dtCh,pos1+1) != -1)
            return false;

        var strMonth = value.substring(0,pos1);
        var strYear = value.substring(pos1+1);

        for (var i = 1; i <= 3; i++)
        {
            if ((strYear.charAt(0) == '0') && (strYear.length > 1))
                strYear = strYear.substring(1);
        }

        if (isInteger(strMonth) == true)
            return false;
        else if (strMonth.length < 1)
            return false;
        else
        {
            strMonth = strMonth.toUpperCase();
            if (!((strMonth == "JAN") || (strMonth == "FEB") || (strMonth == "MAR") || (strMonth == "APR") || (strMonth == "MAY") || (strMonth == "JUN") || (strMonth == "JUL") || (strMonth == "AUG") || (strMonth == "SEP") || (strMonth == "OCT") || (strMonth == "NOV") || (strMonth == "DEC")))
                return false;
        }

        var year = 0;
        if (isInteger(strYear) == true)
            year = parseInt(strYear);
        else
            return false;

        if ((strYear.length != 4) || (year == 0) || (year < minYear) || (year > maxYear))
            return false;

        return true;

        //var pos1 = value.indexOf(dtCh);
        //if ((pos1 == -1))
        //  return false;
        //if (value.indexOf(dtCh,pos1+1) != -1)
        //  return false;

        //var strMonth = value.substring(0,pos1);
        //var strYear = value.substring(pos1+1);

        //for (var i = 1; i <= 3; i++)
        //{
        //  if ((strYear.charAt(0) == '0') && (strYear.length > 1))
        //      strYear = strYear.substring(1);
        //}

        //var month = 0;
        //var year = 0;
        //if (isInteger(strMonth) == true)
        //  month = parseInt(strMonth);
        //else
        //  return false;
        //if (isInteger(strYear) == true)
        //  year = parseInt(strYear);
        //else
        //  return false;

        //if ((strMonth.length < 1) || (month < 1) || (month > 12))
        //  return false;
        //if ((strYear.length != 4) || (year == 0) || (year < minYear) || (year > maxYear))
        //  return false;

        //return true;
    }

    //Require addMsg()
    //Require isTxtDate()
    function chkTxtDate(field, fieldName, required)
    {
		if (field.value != "")
        { 		
			if (isTxtDate(field.value) == false)
			{
				if (langId == 'cht')
				{
					addMsg(fieldName + '必須是日期格式(DD/MM/YYYY)。', field);
				}
				else if (langId == 'chs')
				{
					addMsg(fieldName + '必须是日期格式(DD/MM/YYYY)。', field);
				}
				else
				{
					addMsg(fieldName + ' should be in date format(DD/MM/YYYY).', field);
				}
				return false;
			}
			else
			{
				return true;
			}		
        }
        else
        {
			if(required)
            {
                return chkEmpty(field, fieldName);
            }
            else
            {
				return true;
            }
        }
    }

    function daysInFebruary (year)
    {
        // February has 29 days in any year evenly divisible by four,
        // EXCEPT for centurial years which are not also divisible by 400.
        return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
    }

    function DaysArray(n)
    {
        for (var i = 1; i <= n; i++)
        {
            this[i] = 31;
            if ((i==4) || (i==6) || (i==9) || (i==11))
                this[i] = 30;
            if (i==2)
                this[i] = 29;
        }
        return this;
    }

    //Require isInteger()
    //Require DaysArray(n)
    //daysInFebruary (year)
    function isTxtDate(value)
    {
        var daysInMonth = DaysArray(12)

        var pos1 = value.indexOf(dtCh);
        var pos2 = value.indexOf(dtCh,pos1+1);
        if ((pos1 == -1) || (pos2 == -1) || ((pos2 - pos1) == 1))
            return false;
        if (value.indexOf(dtCh,pos2+1) != -1)
            return false;

        var strDay = value.substring(0,pos1);
        var strMonth = value.substring(pos1+1,pos2);
        var strYear = value.substring(pos2+1);
        if ((strDay.charAt(0) == '0') && (strDay.length > 1))
            strDay = strDay.substring(1);
        if ((strMonth.charAt(0) == '0') && (strMonth.length > 1))
            strMonth = strMonth.substring(1);
        for (var i = 1; i <= 3; i++)
        {
            if ((strYear.charAt(0) == '0') && (strYear.length > 1))
                strYear = strYear.substring(1);
        }
        var day = 0;
        var month = 0;
        var year = 0;
        if (isInteger(strDay) == true)
            day = parseInt(strDay);
        else
            return false;
        if (isInteger(strMonth) == true)
            month = parseInt(strMonth);
        else
            return false;
        if (isInteger(strYear) == true)
            year = parseInt(strYear);
        else
            return false;

        if ((strMonth.length < 1) || (month < 1) || (month > 12))
            return false;
        if ((strDay.length < 1) || (day < 1) || (day > 31) || ((month == 2) && (day > daysInFebruary(year))) || (day > daysInMonth[month]))
            return false;
        if ((strYear.length != 4) || (year == 0) || (year < minYear) || (year > maxYear))
            return false;

        return true;
    }

    //Require isDateComp()
    //Require addMsg()
    function chkDateComp(field1, fieldName1, field2, fieldName2)
    {
        if (isDateComp(field1.value, field2.value) == false)
        {
            addMsg(fieldName2 + ' < ' + fieldName1, null);
            return false;
        }
        else
        {
            return true;
        }
    }

    function isDateComp(value1, value2)
    {
        var daysInMonth = DaysArray(12)

        var value1_pos1 = value1.indexOf(dtCh);
        var value1_pos2 = value1.indexOf(dtCh,value1_pos1+1);
        var value2_pos1 = value2.indexOf(dtCh);
        var value2_pos2 = value2.indexOf(dtCh,value2_pos1+1);

        var value1_strDay = value1.substring(0,value1_pos1);
        var value1_strMonth = value1.substring(value1_pos1+1,value1_pos2);
        var value1_strYear = value1.substring(value1_pos2+1);
        var value2_strDay = value2.substring(0,value2_pos1);
        var value2_strMonth = value2.substring(value2_pos1+1,value2_pos2);
        var value2_strYear = value2.substring(value2_pos2+1);

        if ((value1_strDay.charAt(0) == '0') && (value1_strDay.length > 1))
            value1_strDay = value1_strDay.substring(1);
        if ((value1_strMonth.charAt(0) == '0') && (value1_strMonth.length > 1))
            value1_strMonth = value1_strMonth.substring(1);
        for (var i = 1; i <= 3; i++)
        {
            if ((value1_strYear.charAt(0) == '0') && (value1_strYear.length > 1))
                value1_strYear = value1_strYear.substring(1);
        }
        if ((value2_strDay.charAt(0) == '0') && (value2_strDay.length > 1))
            value2_strDay = value2_strDay.substring(1);
        if ((value2_strMonth.charAt(0) == '0') && (value2_strMonth.length > 1))
            value2_strMonth = value2_strMonth.substring(1);
        for (var i = 1; i <= 3; i++)
        {
            if ((value2_strYear.charAt(0) == '0') && (value2_strYear.length > 1))
                value2_strYear = value2_strYear.substring(1);
        }

        var value1_day = parseInt(value1_strDay);
        var value1_month = parseInt(value1_strMonth);
        var value1_year = parseInt(value1_strYear);
        var value2_day = parseInt(value2_strDay);
        var value2_month = parseInt(value2_strMonth);
        var value2_year = parseInt(value2_strYear);

        if (value2_year > value1_year)
            return true;
        else if ((value2_month > value1_month) && (value2_year == value1_year))
            return true;
        else if ((value2_day >= value1_day) && (value2_month == value1_month) && (value2_year == value1_year))
            return true;
        else
            return false;
    }

    function isDateEqual(value1, value2)
    {
        var daysInMonth = DaysArray(12)

        var value1_pos1 = value1.indexOf(dtCh);
        var value1_pos2 = value1.indexOf(dtCh,value1_pos1+1);
        var value2_pos1 = value2.indexOf(dtCh);
        var value2_pos2 = value2.indexOf(dtCh,value2_pos1+1);

        var value1_strDay = value1.substring(0,value1_pos1);
        var value1_strMonth = value1.substring(value1_pos1+1,value1_pos2);
        var value1_strYear = value1.substring(value1_pos2+1);
        var value2_strDay = value2.substring(0,value2_pos1);
        var value2_strMonth = value2.substring(value2_pos1+1,value2_pos2);
        var value2_strYear = value2.substring(value2_pos2+1);

        if ((value1_strDay.charAt(0) == '0') && (value1_strDay.length > 1))
            value1_strDay = value1_strDay.substring(1);
        if ((value1_strMonth.charAt(0) == '0') && (value1_strMonth.length > 1))
            value1_strMonth = value1_strMonth.substring(1);
        for (var i = 1; i <= 3; i++)
        {
            if ((value1_strYear.charAt(0) == '0') && (value1_strYear.length > 1))
                value1_strYear = value1_strYear.substring(1);
        }
        if ((value2_strDay.charAt(0) == '0') && (value2_strDay.length > 1))
            value2_strDay = value2_strDay.substring(1);
        if ((value2_strMonth.charAt(0) == '0') && (value2_strMonth.length > 1))
            value2_strMonth = value2_strMonth.substring(1);
        for (var i = 1; i <= 3; i++)
        {
            if ((value2_strYear.charAt(0) == '0') && (value2_strYear.length > 1))
                value2_strYear = value2_strYear.substring(1);
        }

        var value1_day = parseInt(value1_strDay);
        var value1_month = parseInt(value1_strMonth);
        var value1_year = parseInt(value1_strYear);
        var value2_day = parseInt(value2_strDay);
        var value2_month = parseInt(value2_strMonth);
        var value2_year = parseInt(value2_strYear);

        if ((value2_year == value1_year) && (value2_month == value1_month) && (value2_day == value1_day))
            return true;
        else
            return false;
    }

    //Require isStrComp()
    //Require addMsg()
    function chkStrComp(field1, fieldName1, field2, fieldName2)
    {
        if (isStrComp(field1.value, field2.value) == false)
        {
            addMsg(fieldName2 + ' <= ' + fieldName1, field1);
            return false;
        }
        else
            return true;
    }

    function chkStrCompEqual(field1, fieldName1, field2, fieldName2)
    {
        if (isStrCompEqual(field1.value, field2.value) == false)
        {
            addMsg(fieldName2 + ' < ' + fieldName1, field1);
            return false;
        }
        else
            return true;
    }
    
    function chkStrCompNotEqual(field1, fieldName1, field2, fieldName2)
    {
        if (field1.value == field2.value)
        {
            addMsg(fieldName2 + ' = ' + fieldName1, field1);
            return false;
        }
        else
            return true;
    }    
    

    function chkValue(fieldobj, should_be_expression, fieldName){
        var isValid = false;
        var should_be_desc = replaceEqual(replaceUnequal(should_be_expression));

        if (fieldobj.value == ''){
            return true;
        }
        else
        {
            var inputstr =  replaceSubstring(fieldobj.value,",","");
            var input = parseFloat(inputstr);

            eval("isValid = (" + input + should_be_expression + ");")
            if (!isValid){
				if (langId == 'cht')
				{
					addMsg(fieldName + '需要' + should_be_desc + '.', fieldobj);
				}
				else if (langId == 'chs')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -