SoFunction
Updated on 2025-03-01

JS Verification Form Part 2

Description: JavaScript script, verify the data items in the form, begin
------------------------------------------------------------------------------- 
*/ 
function checkForm(objFrm){ 
var len = 0; 
len = ; 
var i = 0; 
var objCheck; 
//Text box
for(i = 0; i < len; i ++){ 
objCheck = [i]; 
if( =="text" && !f_checkTextValid(objCheck) ){ 
return false; 



//Drop down box
for(i = 0; i < len; i ++){ 
objCheck = [i]; 
if( =="select-one" && !f_checkSelectValid(objCheck) ){ 
return false; 



//Time period is valid
if( f_checkStartAndEndDate(objFrm) == false) return false; 
return true; 

function f_checkSelectValid(obj){ 
//alert("check select"); 
if( <= 0){ 
alert("No data on the drop-down box!");
return false; 

return true; 

function f_checkStartAndEndDate(frm){ 
var len = ; 
if(len == null && len == 0) return true; 
var i=0; 
var temp; 
var objCheck; 
var objStartDate; 
var objEndDate; 
//alert("start date period check"); 
try{ 
for(i=0; i< len ; i++){ 
objCheck = [i]; 
temp = ; 
if( ("startDate") >0 ||("beginDate")>0 ) 
objStartDate = objCheck; 
if( ("endDate") > 0 ) 
objEndDate = objCheck; 

//alert(); 
//alert(); 
if(==null ||  =="" ||  ==null ||  ==""){ 
return true; 

return checkTwoDate(, ); 
//alert("end date period check"); 
}catch(E){} 
return true; 

function f_checkTextValid(obj){ 
//Not empty
if(("isNeed") != null){ 
if(f_isNotNull(obj) == false) return false; 

//Not exceeding the length
if(("maxlength") != null){ 
if(f_checkLength(obj) == false) return false; 

var checkType =""; 
checkType = ("checkType"); 
if(checkType==null||checkType=="") return true; 
// 
if (("number") >=0){ 
if(f_isNumber(obj) == false)  return false; 
if(f_checkNumType(obj,checkType) == false)  return false; 

// 
if (("positive") >=0){ 
if(f_isNumber(obj) == false)  return false; 
if(f_isPositive(obj)==false)  return false; 
if(f_checkNumType(obj,checkType) == false)  return false; 

if (("date") >=0){ 
if(f_checkDate(obj) == false) return false; 

/* 
switch(checkType){ 
case "number": if(f_isNumber(obj) == false) return false;break; 
case "date": if(f_checkDate(obj) == false) return false;break; 
default: 

*/ 
return true; 

function f_isNotNull(obj){ 
if( == ""){ 
f_alert(obj, " Non-null value is not allowed!");
return false; 

return true; 

function f_isNumber(obj){ 
if(isNaN()){ 
f_alert(obj," should be a numerical type");
return false; 


return true; 

function f_checkDate(obj) { 
if(checkDate() ==false){ 
f_alert(obj," Not a legal date format!");
return false; 


return true; 

function f_checkLength(obj){ 
if(getTotalBytes(obj) > ( ("maxlength") ) ){ 
f_alert(obj," Exceed length limit!");
return false; 


return true; 

function  f_alert(obj,alertStr){ 
var fielName = ("fieldName"); 
if(fielName == null) 
fielName = ""; 
alert(fielName + "\n" +alertStr); 
(); 
(); 

function f_checkNumType(obj, numType){ 
//Hypothesis: The number type judgment has been made
var strTemp; 
var numpric; 
var numLen; 
var strArr; 
var defaultLen = 19; 
var defaultpric = 5; 
try{ 
if(numType == null|| numType =="") return f_checkNumLenPrec(obj,defaultLen, defaultpric); 
if(("(") < 0 || (")") < 0 ) return f_checkNumLenPrec(obj,defaultLen, defaultpric); 
strTemp = ( ("(") + 1 ,(")") - ("(") -1 ); 
if(strTemp == null||strTemp =="") return f_checkNumLenPrec(obj,defaultLen, defaultpric); 
strArr = (","); 
numLen = ( strArr[0] ); 
numpric = ( strArr[1] ); 
return f_checkNumLenPrec(obj,numLen, numpric); 
}catch(e){ 
alert("in f_checkNumType = " + e); 
return f_checkNumLenPrec(obj,defaultLen, defaultpric); 


function f_checkNumLenPrec(obj, len, pric){ 
var numReg; 
var value = ; 
var strValueTemp, strInt, strDec; 
//alert(value + "=====" + len + "====="+ pric); 
try{ 

numReg =/[\-]/; 
strValueTemp = (numReg, ""); 
strValueTemp = (numReg, ""); 
//Integer
if(pric==0){ 
numReg =/[\.]/; 
//alert((value)); 
if((value) == true){ 
f_alert(obj, "The input must be of integer type!");
return false; 



if((".") < 0 ){ 
//alert("lennth==" + strValueTemp); 

if( >( len - pric)){ 
f_alert(obj, "Integer bits cannot exceed "+ (len - pric) +"bit");
return false; 

}else{ 
strInt = ( 0, (".") ); 

//alert("lennth==" + strInt); 

if( >( len - pric)){ 
f_alert(obj, "Integer bits cannot exceed "+ (len - pric) +"bit");
return false; 


strDec = ( ((".")+1),  ); 

//alert("pric==" + strDec); 

if( > pric){ 
f_alert(obj, "The decimal digit cannot exceed "+  pric +"bit");
return false; 



return true; 
}catch(e){ 
alert("in f_checkNumLenPrec = " + e); 
return false; 


function f_isPositive(obj){ 
var numReg =/[\-]/; 
if(() == true){ 
f_alert(obj, "must be positive!");
return false; 

return true; 


/* 
function selectedCheckboxCount(form) 
Function description: Count the optional options selected in Form
Parameter description:
form: The specified form
*/ 
function selectedCheckboxCount(form){ 
var length =0; 
var i=0; 
var count =0; 
eles = ; 
while(i<){ 
obj= (i); 
//type = ("type").nodeValue; 
type = ; 
if(type == "checkbox"){ 
if(){ 
count++; 


i++; 

return count; 

//Get the byte length
function getByteLen(str) 

var l = ; 
var n = l; 
for ( var i=0; i<l; i++ ) 
if ( (i) <0 || (i) >255 ) 
n=n+1; 
return n 

/* 
illustrate:
1. Clear the data in the table (0.0 and 0)
2. If there is no data in the cell, a space will be automatically added.
3. Clear the checkbox of blank lines
Parameters:
clearzero: Whether to clear "0" and "0.0", false not clear or true clear (default is true)
tablename: The name of the table to be cleared, default is sortTable
*/ 
function clear_table(clearzero,tablename) 

var tobject; 
if(tablename==null) 
tobject=gmobj("sortTable"); 
else 
tobject=gmobj(tablename); 
//If the table is not defined, no filtering is performed.
if(tobject==null) 
return; 

//If the function call parameter is empty, it means that 0 and 0.0 are to be cleared; otherwise, do not clear 0 and 0.0.
var clear = (clearzero==null)?true:clearzero; 
//Clear 0, 0.0 and fill in the spaces
var rows = ; 
var j=0; 
for(var i=0;i<;i++) 

//Get the property clear of the first cell. If it is 1, it means that there is no data in the row, then all data in the row will be cleared.
while([i].cells[j] != null) 

if(clear) 

if([i].cells[j].innerHTML==0 ||[i].cells[j].innerHTML==0.0||[i].cells[j].innerHTML=="") 
[i].cells[j].innerText=" "; 

else 

if ([i].cells[j].innerHTML=="") 
[i].cells[j].innerText=" "; 

j++; 

j=0; 

return true; 

function gmobj(mtxt)  /* Get object by object name */ 

if () { 
m=(mtxt); 
} else if () { 
m=[mtxt]; 
} else if () { 
m=[mtxt]; 

return m; 

/* 
------------------------------------------------------------------------------- 
Description: JavaScript script, verify the data items in the form  end
------------------------------------------------------------------------------- 
*/ 
/* 
Purpose: Check whether the input string is in a decimal number format, which can be a negative number (and meets the specified accuracy)
Input: str: string
l: Total number of digits
d: the number of digits after the decimal point
return:
If true is returned by verification, otherwise false will be returned.
*/ 
function isDecimal( str,l,d ){   
if(isInteger(str)) { 
if (l==null)  return true; 
if (str<0) l--; 
if (<=l) return true; 

var re = /^[-]{0,1}(\d+)[\.]+(\d+)$/; 
if ((str)) { 
if (l==null)  return true; 
if (d==null) d=0; 
if(RegExp.$1==0&&RegExp.$2==0) return false; 
if (RegExp.$+RegExp.$<=l 
&& RegExp.$<=d)  return true; 

return false; 

onclick="isNull('');" 
Co--refers to this page   PageForm--refers to formName  CompetitorName--refers to the text column name