function isFirstMatch(str1,str2) {
var index = str1.indexOf(str2);
if(index==0) return true;
return false; } /*
用途:字符1是包含字符串2
输入:str1:字符串;str2:被包含的字符串
返回:如果通过验证返回true,否则返回false */
function isMatch(str1,str2) {
var index = str1.indexOf(str2);
if(index==-1) return false;
return true; } /*
用途:检查输入的起止日期是否正确,规则为两个日期的格式正确,
且结束如期>=起始日期
输入:
startDate:起始日期,字符串
endDate:结束如期,字符串
返回:
如果通过验证返回true,否则返回false */
function checkTwoDate( startDate,endDate ) {
if( !isDate(startDate) ) {
alert(\起始日期不正确!\
return false;
} else if( !isDate(endDate) ) {
alert(\终止日期不正确!\
return false;
} else if( startDate > endDate ) {
alert(\起始日期不能大于终止日期!\
return false; }
return true; } /*
用途:检查输入的Email信箱格式是否正确
输入:
strEmail:字符串
返回:
如果通过验证返回true,否则返回false */
function checkEmail(strEmail) {
//var emailReg = /^[_a-z0-9]+@([_a-z0-9]+\\.)+[a-z0-9]{2,3}$/;
var emailReg = /^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/;
if( emailReg.test(strEmail) ){
return true;
}else{
alert(\您输入的Email地址格式不正确!\
return false; } } /*
用途:检查输入的电话号码格式是否正确
输入:
strPhone:字符串
返回:
如果通过验证返回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 if( document.all(checkboxID).item( i ).checked ) { check += 1; } } }else{ if( document.all(checkboxID).checked ) check = 1; } return check; }