<div class="cnblogs_code">
*/
function isIP(strIP) {
if (isNull(strIP)) return false;
var re=/^(\d+).(\d+).(\d+).(\d+)$/g //匹配IP地址的正则表达式
if(re.test(strIP))
{
if( RegExp.$1 <span style="color: #0000ff"><<span style="color: #800000">256 <span style="color: #ff0000">&& RegExp.$2<256 && RegExp.$3<256 && RegExp.$4<256) return true;
}
return false;
}/
用途:检查输入字符串是否为空或者全部都是空格
输入:str
返回:
如果全是空返回true,否则返回false
/
function isNull( str ){
if ( str <span style="color: #0000ff">== <span style="color: #ff0000">"" ) return true;
var regu <span style="color: #0000ff">= "^[ ]+$"<span style="color: #ff0000">;
var re <span style="color: #0000ff">= new <span style="color: #ff0000">RegExp(regu);
return re.test(str);
}/*
用途:检查输入对象的值是否符合整数格式
输入:str 输入的字符串
返回:如果通过验证返回true,否则返回false*/
function isInteger( str ){
var regu <span style="color: #0000ff">= /^[-]{0,1}[0-9]{1,}$/;
<span style="color: #ff0000">return regu.test(str);
}/*
用途:检查输入手机号码是否正确
输入:
s:字符串
返回:
如果通过验证返回true,否则返回false*/
function checkMobile( s ){
var regu <span style="color: #0000ff">=/^[1][3][0-9]{9}$/;
<span style="color: #ff0000">var re <span style="color: #0000ff">= new <span style="color: #ff0000">RegExp(regu);
if (re.test(s)) {
return true;
}else{
return false;
}
}/*
用途:检查输入字符串是否符合正整数格式
输入:
s:字符串
返回:
如果通过验证返回true,否则返回false*/
function isNumber( s ){
var regu <span style="color: #0000ff">= "^[0-9]+$"<span style="color: #ff0000">;
var re <span style="color: #0000ff">= new <span style="color: #ff0000">RegExp(regu);
if (s.search(re) !<span style="color: #0000ff">= -1) <span style="color: #ff0000">{
return true;
} else {
return false;
}
}/*
用途:检查输入字符串是否是带小数的数字格式,可以是负数
输入:
s:字符串
返回:
如果通过验证返回true,否则返回false*/
function isDecimal( str ){
if(isInteger(str)) return true;
var re <span style="color: #0000ff">= /^[-]{0,1}(\d+)[.]+(\d+)$/;
<span style="color: #ff0000">if (re.test(str)) {
if(RegExp.$1<span style="color: #0000ff">==0&&RegExp.$2==0) <span style="color: #ff0000">return false;
return true;
} else {
return false;
}
}/*
用途:检查输入对象的值是否符合端口号格式
输入:str 输入的字符串
返回:如果通过验证返回true,否则返回false*/
function isPort( str ){
return (isNumber(str) && str<65536);
}/*
用途:检查输入对象的值是否符合E-Mail格式
输入:str 输入的字符串
返回:如果通过验证返回true,否则返回false*/
function isEmail( str ){
var myReg <span style="color: #0000ff">= /^[-_A-Za-z0-9]+@([_A-Za-z0-9]+.)+[A-Za-z0-9]{2,3}$/;
<span style="color: #ff0000">if(myReg.test(str)) return true;
return false;
}/*
用途:检查输入字符串是否符合金额格式
格式定义为带小数的正数,小数点后最多三位
输入:
s:字符串
返回:
如果通过验证返回true,否则返回false/
function isMoney( s ){
var regu <span style="color: #0000ff">= "^[0-9]+[.][0-9]{0,3}$"<span style="color: #ff0000">;
var re <span style="color: #0000ff">= new <span style="color: #ff0000">RegExp(regu);
if (re.test(s)) {
return true;
} else {
return false;
}
}
/
用途:检查输入字符串是否只由英文字母和数字和下划线组成
输入:
s:字符串
返回:
如果通过验证返回true,否则返回false*/
function isNumberOr_Letter( s ){//判断是否是数字或字母var regu <span style="color: #0000ff">= "^[0-9a-zA-Z_]+$"<span style="color: #ff0000">;
var re <span style="color: #0000ff">= new <span style="color: #ff0000">RegExp(regu);
if (re.test(s)) {
return true;
}else{
return false;
}
}
/*
用途:检查输入字符串是否只由英文字母和数字组成
输入:
s:字符串
返回:
如果通过验证返回true,否则返回false*/
function isNumberOrLetter( s ){//判断是否是数字或字母var regu <span style="color: #0000ff">= "^[0-9a-zA-Z]+$"<span style="color: #ff0000">;
var re <span style="color: #0000ff">= new <span style="color: #ff0000">RegExp(regu);
if (re.test(s)) {
return true;
}else{
return false;
}
}
/*
用途:检查输入字符串是否只由汉字、字母、数字组成
输入:
value:字符串
返回:
如果通过验证返回true,否则返回false*/
function isChinaOrNumbOrLett( s ){//判断是否是汉字、字母、数字组成var regu <span style="color: #0000ff">= "^[0-9a-zA-Z\u4e00-\u9fa5]+$"<span style="color: #ff0000">;
var re <span style="color: #0000ff">= new <span style="color: #ff0000">RegExp(regu);
if (re.test(s)) {
return true;
}else{
return false;
}
}/
用途:判断是否是日期
输入:date:日期;fmt:日期格式
返回:如果通过验证返回true,否则返回false
/
function isDate( date,fmt ) {
if (fmt<span style="color: #0000ff">==null) <span style="color: #ff0000">fmt<span style="color: #0000ff">="yyyyMMdd"<span style="color: #ff0000">;
var yIndex <span style="color: #0000ff">= fmt.indexOf("yyyy");
<span style="color: #ff0000">if(yIndex<span style="color: #0000ff">==-1) <span style="color: #ff0000">return false;
var year <span style="color: #0000ff">= date.substring(yIndex,yIndex+4);
<span style="color: #ff0000">var mIndex <span style="color: #0000ff">= fmt.indexOf("MM");
<span style="color: #ff0000">if(mIndex<span style="color: #0000ff">==-1) <span style="color: #ff0000">return false;
var month <span style="color: #0000ff">= date.substring(mIndex,mIndex+2);
<span style="color: #ff0000">var dIndex <span style="color: #0000ff">= fmt.indexOf("dd");
<span style="color: #ff0000">if(dIndex<span style="color: #0000ff">==-1) <span style="color: #ff0000">return false;
var day <span style="color: #0000ff">= date.substring(dIndex,dIndex+2);
<span style="color: #ff0000">if(!isNumber(year)||year<span style="color: #0000ff">>"2100" || year<span style="color: #0000ff"><<span style="color: #800000"> "1900<span style="color: #ff0000">") return false;
if(!isNumber(month)||month<span style="color: #0000ff">>"12" || month<span style="color: #0000ff"><<span style="color: #800000"> "01<span style="color: #ff0000">") return false;
if(day<span style="color: #0000ff">>getMaxDay(year,month) || day<span style="color: #0000ff"><<span style="color: #800000"> "01<span style="color: #ff0000">") return false;
return true;
}function getMaxDay(year,month) {
if(month<span style="color: #0000ff">==4||month==6||month==9||month==11)
<span style="color: #ff0000">return "30";
if(month<span style="color: #0000ff">==2)
<span style="color: #ff0000">if(year%4<span style="color: #0000ff">==0&&year%100!=0 <span style="color: #ff0000">|| year%400<span style="color: #0000ff">==0)
<span style="color: #ff0000">return "29";
else
return "28";
return "31";
}/*
用途:字符1是否以字符串2结束
输入:str1:字符串;str2:被包含的字符串
返回:如果通过验证返回true,否则返回false*/
function isLastMatch(str1,str2)
{
var index <span style="color: #0000ff">= str1.lastIndexOf(str2);
<span style="color: #ff0000">if(str1.length<span style="color: #0000ff">==index+str2.length) <span style="color: #ff0000">return true;
return false;
}/*
用途:字符1是否以字符串2开始
输入:str1:字符串;str2:被包含的字符串
返回:如果通过验证返回true,否则返回false*/
function isFirstMatch(str1,str2)
{
var index <span style="color: #0000ff">= str1.indexOf(str2);
<span style="color: #ff0000">if(index<span style="color: #0000ff">==0) <span style="color: #ff0000">return true;
return false;
}/*
用途:字符1是包含字符串2
输入:str1:字符串;str2:被包含的字符串
返回:如果通过验证返回true,否则返回false*/
function isMatch(str1,str2)
{
var index <span style="color: #0000ff">= str1.indexOf(str2);
<span style="color: #ff0000">if(index<span style="color: #0000ff">==-1) <span style="color: #ff0000">return false;
return true;
}/*
用途:检查输入的起止日期是否正确,规则为两个日期的格式正确,
且结束如期<span style="color: #0000ff">><span style="color: #000000">=起始日期
输入:
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<span style="color: #0000ff"><<span style="color: #800000">document<span style="color: #ff0000">.all(checkBoxID).length; i++ ) {
if( document.all(checkBoxID).item( i ).checked ) {
check +<span style="color: #0000ff">= 1;
<span style="color: #ff0000">}}
}else{
if( document.all(checkBoxID).checked )
check <span style="color: #0000ff">= 1;
<span style="color: #ff0000">}
return check;
}function getTotalBytes(varField) {
if(varField <span style="color: #0000ff">== <span style="color: #ff0000">null)
return -1;var totalCount <span style="color: #0000ff">= 0;
<span style="color: #ff0000">for (i <span style="color: #0000ff">= 0; <span style="color: #ff0000">i< varField.value.length; i++) {
if (varField.value.charCodeAt(i) <span style="color: #0000ff">><span style="color: #000000"> 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<span style="color: #0000ff"><<span style="color: #800000">document<span style="color: #ff0000">.all(checkBoxID).length; i++ ){
if( document.all(checkBoxID).item( i ).checked ){
value <span style="color: #0000ff">= document.all(checkBoxID).item(i).value;
<span style="color: #ff0000">break;
}
}
} else {
if( document.all(checkBoxID).checked )
value <span style="color: #0000ff">= document.all(checkBoxID).value;
<span style="color: #ff0000">}
return value;
}function getFirstSelectedIndex( checkBoxID ){
var value <span style="color: #0000ff">= -2;
<span style="color: #ff0000">var i<span style="color: #0000ff">=0;
<span style="color: #ff0000">if( document.all(checkBoxID).length <span style="color: #0000ff">><span style="color: #000000"> 0 ){
for( i=0; i<span style="color: #0000ff"><<span style="color: #800000">document<span style="color: #ff0000">.all(checkBoxID).length; i++ ) {
if( document.all(checkBoxID).item( i ).checked ) {
value <span style="color: #0000ff">= i;
<span style="color: #ff0000">break;
}
}
} else {
if( document.all(checkBoxID).checked )
value <span style="color: #0000ff">= -1;
<span style="color: #ff0000">}
return value;
}function selectAll( checkBoxID,status ){
if( document.all(checkBoxID) <span style="color: #0000ff">== <span style="color: #ff0000">null)
return;if( document.all(checkBoxID).length <span style="color: #0000ff">><span style="color: #000000"> 0 ){
for( i=0; i<span style="color: #0000ff"><<span style="color: #800000">document<span style="color: #ff0000">.all(checkBoxID).length; i++ ){document.all(checkBoxID).item( i ).checked <span style="color: #0000ff">= status;
<span style="color: #ff0000">}
} else {
document.all(checkBoxID).checked <span style="color: #0000ff">= status;
<span style="color: #ff0000">}
}function selectInverse( checkBoxID ) {
if( document.all(checkBoxID) <span style="color: #0000ff">== <span style="color: #ff0000">null)
return;if( document.all(checkBoxID).length <span style="color: #0000ff">><span style="color: #000000"> 0 ) {
for( i=0; i<span style="color: #0000ff"><<span style="color: #800000">document<span style="color: #ff0000">.all(checkBoxID).length; i++ ) {
document.all(checkBoxID).item( i ).checked <span style="color: #0000ff">= !document.all(checkBoxID).item( <span style="color: #ff0000">i ).checked;
}
} else {
document.all(checkBoxID).checked <span style="color: #0000ff">= !document.all(checkBoxID).checked;
<span style="color: #ff0000">}
}function checkDate( value ) {
if(value<span style="color: #0000ff">=='') <span style="color: #ff0000">return true;
if(value.length!<span style="color: #0000ff">=8 <span style="color: #ff0000">|| !isNumber(value)) return false;
var year <span style="color: #0000ff">= value.substring(0,4);
<span style="color: #ff0000">if(year<span style="color: #0000ff">>"2100" || year<span style="color: #0000ff"><<span style="color: #800000"> "1900<span style="color: #ff0000">")
return false;var month <span style="color: #0000ff">= value.substring(4,6);
<span style="color: #ff0000">if(month<span style="color: #0000ff">>"12" || month<span style="color: #0000ff"><<span style="color: #800000"> "01<span style="color: #ff0000">") return false;var day <span style="color: #0000ff">= value.substring(6,8);
<span style="color: #ff0000">if(day<span style="color: #0000ff">>getMaxDay(year,month) || day<span style="color: #0000ff"><<span style="color: #800000"> "01<span style="color: #ff0000">") return false;return true;
}/*
用途:检查输入的起止日期是否正确,规则为两个日期的格式正确或都为空
且结束日期<span style="color: #0000ff">><span style="color: #000000">=起始日期
输入:
startDate:起始日期,字符串
endDate: 结束日期,字符串
返回:
如果通过验证返回true,否则返回false*/
function checkPeriod( startDate,endDate ) {
if( !checkDate(startDate) ) {
alert("起始日期不正确!");
return false;
} else if( !checkDate(endDate) ) {
alert("终止日期不正确!");
return false;
} else if( startDate > endDate ) {
alert("起始日期不能大于终止日期!");
return false;
}
return true;
}/*
用途:检查证券代码是否正确
输入:
secCode:证券代码
返回:
如果通过验证返回true,否则返回false*/
function checkSecCode( secCode ) {
if( secCode.length !=6 ){
alert("证券代码长度应该为6位");
return false;
}if(!isNumber( secCode ) ){
alert("证券代码只能包含数字");return false;
}
return true;
}/****
function:cTrim(sInputString,iType)
description:字符串去空格的函数
parameters:iType:1=去掉字符串左边的空格2=去掉字符串左边的空格
0=去掉字符串左边和右边的空格
return value:去掉空格的字符串
****/
function cTrim(sInputString,iType)
{
var sTmpStr = ' ';
var i = -1;if(iType == 0 || iType == 1)
{
while(sTmpStr == ' ')
{
++i;
sTmpStr = sInputString.substr(i,1);
}
sInputString = sInputString.substring(i);
}if(iType == 0 || iType == 2)
{
sTmpStr = ' ';
i = sInputString.length;
while(sTmpStr == ' ')
{
--i;
sTmpStr = sInputString.substr(i,1);
}
sInputString = sInputString.substring(0,i+1);
}
return sInputString;
}