📄 general.js
字号:
{
addMsg(fieldName + '需要' + should_be_desc + '.', fieldobj);
}
else
{
addMsg(fieldName + ' should be ' + should_be_desc + '.', fieldobj);
}
return false;
}
else
{
return true;
}
}
}
function isStrComp(value1, value2)
{
if (value2 > value1)
return true;
else
return false;
}
function isStrCompEqual(value1, value2)
{
if (value2 >= value1)
return true;
else
return false;
}
function addMsg(msg, field)
{
errorMsg += '-' + ' ' + msg;
errorMsg += '\n';
errorNum += 1;
if (errorNum == 1)
{
if (field != null)
if (field.type != "hidden" && !field.disabled)
errorFocus = field;
}
}
function getSelectValue(selectObject)
{
return selectObject.options[selectObject.selectedIndex].value;
}
function getSelectText(selectObject)
{
return selectObject.options[selectObject.selectedIndex].text;
}
function OptionSelectByValue(selectObj, selectValue)
{
for (var i=0;i<selectObj.options.length; i++)
{
if (selectObj.options[i].value == selectValue)
{
selectObj.selectedIndex = i;
}
}
}
function chkEmail (field, fieldName, required)
{
emailStr = field.value;
emailStr = emailStr.toLowerCase();
if (emailStr != "")
{
/* The following pattern is used to check if the entered e-mail address
fits the user@domain format. It also is used to separate the username
from the domain. */
var isWrongFormat = 0;
var pos1 = emailStr.indexOf('@');
var pos2 = emailStr.indexOf('.');
if (pos2 < pos1){
pos2 = emailStr.substring(pos1+1,emailStr.length).indexOf('.');
if (pos2 != -1){
pos2 = (pos1+1) + pos2
}
}
if ((pos1 == -1) || (pos2 == -1) || ((pos2 - pos1) == 1) || pos1 == 0)
isWrongFormat = 1;
strUserName = emailStr.substring(0,pos1);
strDomain = emailStr.substring(pos1+1,pos2);
strCom = emailStr.substring(pos2+1,emailStr.length);
if (isWrongFormat==0)
{
if (!(isSpecialChar(strUserName)
&&isSpecialChar(strDomain)
&&isSpecialChar(strCom)))
{
isWrongFormat = 1;
}
}
if (isWrongFormat>0) {
/*Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
if (langId == 'cht')
{
addMsg(fieldName + '必須是電子郵件地址格式。', field);
}
else if (langId == 'chs')
{
addMsg(fieldName + '必须是电子邮件地址格式。', field);
}
else
{
addMsg(fieldName + ' should be email address format.', field);
}
return false;
}
else{
return true;
}
}
else
{
if (required){
if (langId == 'cht')
{
addMsg('請輸入' + fieldName + '。', field);
}
else if (langId == 'chs')
{
addMsg('请输入' + fieldName + '。', field);
}
else{
addMsg('Please enter the ' + fieldName + '.', field);
}
return false;
}
else{
return true;
}
}
}
function isSpecialChar(value){
var strValidChars = "\'\"<>!#$%^&,()@";
var blnResult = true;
var i = 0;
for (i=0; i<value.length && blnResult == true; i++)
{
strChar = value.charAt(i);
if (strValidChars.indexOf(strChar) > 0 )
{
blnResult = false;
}
}
return blnResult;
}
function trim(inputString) {
// Removes leading and trailing spaces from the passed string. Also removes
// consecutive spaces and replaces it with one space. If something besides
// a string is passed in (null, custom object, etc.) then return the input.
if (typeof inputString != "string") { return inputString; }
var retValue = inputString;
var ch = retValue.substring(0, 1);
while (ch == " ") { // Check for spaces at the beginning of the string
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") { // Check for spaces at the end of the string
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings
}
return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
function replaceUnequal(str)
{
return replaceSubstring(str, '!=', '<>');
}
function replaceEqual(str)
{
return replaceSubstring(str, '==', '=');
}
function replaceSubstring(inputString, fromString, toString) {
// Goes through the inputString and replaces every occurrence of fromString with toString
var temp = inputString;
if (fromString == "") {
return inputString;
}
if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
while (temp.indexOf(fromString) != -1) {
var toTheLeft = temp.substring(0, temp.indexOf(fromString));
var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
temp = toTheLeft + toString + toTheRight;
}
} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
var midStrings = new Array("~", "`", "_", "^", "#");
var midStringLen = 1;
var midString = "";
// Find a string that doesn't exist in the inputString to be used
// as an "inbetween" string
while (midString == "") {
for (var i=0; i < midStrings.length; i++) {
var tempMidString = "";
for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
if (fromString.indexOf(tempMidString) == -1) {
midString = tempMidString;
i = midStrings.length + 1;
}
}
} // Keep on going until we build an "inbetween" string that doesn't exist
// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
while (temp.indexOf(fromString) != -1) {
var toTheLeft = temp.substring(0, temp.indexOf(fromString));
var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
temp = toTheLeft + midString + toTheRight;
}
// Next, replace the "inbetween" string with the "toString"
while (temp.indexOf(midString) != -1) {
var toTheLeft = temp.substring(0, temp.indexOf(midString));
var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
temp = toTheLeft + toString + toTheRight;
}
} // Ends the check to see if the string being replaced is part of the replacement string or not
return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function
//Upper case the letter when keypress
function uppercase()
{
key = window.event.keyCode;
if ((key > 0x60) && (key < 0x7B))
window.event.keyCode = key-0x20;
}
function doUppercase(fieldId) {
var field = document.getElementById(fieldId);
if (field && field.value) field.value = field.value.toUpperCase();
}
function getTextareaLines(field_ref,field_cols) {
var stringremain = field_ref.value;
var pos = 0;
var lines = 0;
var stringtemplines = 0;
var stringtemplines = 0;
do{
if (stringremain.length > 0)
{
pos = stringremain.indexOf("\n");
if (pos > 0)
{
stringtemp = stringremain.substring(0,pos-1);
stringremain = stringremain.substring(pos + 1, stringremain.length);
}
else
{
stringtemp = stringremain;
stringremain = "";
}
if (stringtemp.length == 0)
{
stringtemplines = 1;
}
else
{
stringtemplines = Math.ceil(stringtemp.length/field_cols);
}
lines = lines + stringtemplines;
}
else
{
pos = -1;
}
}while(pos > 0)
return lines;
}
//return false if the object's character exceed the limit
function checkMaxLength(obj, maxLength)
{
if (obj.value.length >= maxLength && event.keyCode != 46 && event.keyCode !=8 && !(event.keyCode >=33 && event.keyCode <=40))
return false;
else
return true;
}
function checkMaxLines(obj, maxLines, cols)
{
if (getTextareaLines(obj, cols) > maxLines && event.keyCode != 46 && event.keyCode !=8 && !(event.keyCode >=33 && event.keyCode <=40 && event.keyCode == 13))
{
return false;
}
else
{
if (event.keyCode == 13 && getTextareaLines(obj, cols) == maxLines)
{
return false;
}
else
{
return true;
}
}
}
function checkMaxLengthLines(obj, maxLength, maxLines, cols){
return checkMaxLines(obj, maxLines, cols) && checkMaxLength(obj, maxLength);
}
function chkLength(field, fielddesc, len)
{
if (field.value.length <= len)
{
return true;
}
else
{
if (langId == 'cht')
{
addMsg(fielddesc + '不可超過' + len + '個字元。', field);
}
else if (langId == 'chs')
{
addMsg(fielddesc + '不可超过' + len + '个字元。', field);
}
else{
addMsg(fielddesc + ' should not exceeds ' + len + ' characters.', field);
}
return false;
}
}
function chkMinLength(field, fielddesc, len)
{
if (field.value.length < len)
{
if (langId == 'cht')
{
addMsg(fielddesc + '最少要有' + len + '個字元。', field);
}
else if (langId == 'chs')
{
addMsg(fielddesc + '最少要有' + len + '个字元。', field);
}
else{
addMsg(fielddesc + ' must have at least ' + len + ' characters.', field);
}
return false;
} else
return true;
}
function chkLines(field, fielddesc, lines, cols)
{
if (getTextareaLines(field,cols) <= lines)
{
return true;
}
else
{
if (langId == 'cht')
{
addMsg(fielddesc + '不可以超过行数限制。', field);
}
else if (langId == 'chs')
{
addMsg(fielddesc + '不可以超過行數限制。', field);
}
else{
addMsg(fielddesc + ' should not exceeds the lines limit.', field);
}
return false;
}
}
function chkTxtTimeToMin(field, fieldName, required)
{
var notblank = true;
if (required)
{
notblank = chkEmpty(field, fieldName)
}
if (notblank && trim(field.value) != '')
{
if (isTxtTimeToMin(field.value) == false)
{
if (langId == 'cht')
{
addMsg(fielddesc + '必須是時間格式(HH:MM)。', field);
}
else if (langId == 'chs')
{
addMsg(fielddesc + '必须是时间格式(HH:MM)。', field);
}
else{
addMsg(fieldName + ' should be in time format(HH:MM).', field);
}
return false;
}
else
return true;
}
else return false;
}
function isTxtTimeToMin(value)
{
if (value == null)
return false;
var pos1 = value.indexOf(":");
if (pos1 == -1 )
return false;
var strHH = value.substring(0,pos1);
var strMM = value.substring(pos1+1);
if (!IsNumeric(strHH, 2,0) || !IsNumeric(strMM, 2,0))
return false;
var intHH = parseInt(strHH);
var intMM = parseInt(strMM);
if (intHH < 0 || intHH > 23 || intMM < 0 || intMM > 59)
return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -