js验证表单大全

2019-06-03 15:09:50刘景俊

返回:
如果通过验证返回true,否则返回false

*/
function checkPhone( strPhone ) {
var phoneRegWithArea = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
var phoneRegNoArea = /^[1-9]{1}[0-9]{5,8}$/;
var prompt = "您输入的电话号码不正确!"
if( strPhone.length > 9 ) {
if( phoneRegWithArea.test(strPhone) ){
return true;
}else{
alert( prompt );
return false;
}
}else{
if( phoneRegNoArea.test( strPhone ) ){
return true;
}else{
alert( prompt );
return false;
}

 
}
}

 
/*
用途:检查复选框被选中的数目
输入:
checkboxID:字符串
返回:
返回该复选框中被选中的数目

*/

function checkSelect( checkboxID ) {
var check = 0;
var i=0;
if( document.all(checkboxID).length > 0 ) {
for(  i=0; i<document.all(checkboxID).length; i++ ) {
if( document.all(checkboxID).item( i ).checked  ) {
check += 1;
}

 

 
}
}else{
if( document.all(checkboxID).checked )
check = 1;
}
return check;
}

function getTotalBytes(varField) {
if(varField == null)
return -1;

var totalCount = 0;
for (i = 0; i< varField.value.length; i++) {
if (varField.value.charCodeAt(i) > 127)
totalCount += 2;
else
totalCount++ ;
}
return totalCount;
}

function getFirstSelectedValue( checkboxID ){
var value = null;
var i=0;
if( document.all(checkboxID).length > 0 ){
for(  i=0; i<document.all(checkboxID).length; i++ ){
if( document.all(checkboxID).item( i ).checked ){
value = document.all(checkboxID).item(i).value;
break;
}
}
} else {
if( document.all(checkboxID).checked )
value = document.all(checkboxID).value;
}
return value;
}

 
function getFirstSelectedIndex( checkboxID ){
var value = -2;
var i=0;
if( document.all(checkboxID).length > 0 ){
for(  i=0; i<document.all(checkboxID).length; i++ ) {
if( document.all(checkboxID).item( i ).checked  ) {
value = i;
break;
}
}
} else {
if( document.all(checkboxID).checked )
value = -1;
}
return value;
}

function selectAll( checkboxID,status ){