js校验

    //用于创建XMLHttpRequest对象
function createXmlHttp()
    {
var xmlHttp =null;
  try {
 xmlHttp = new XMLHttpRequest(); // Mozilla, Safari, Opera, IE7
} catch (e) { //before IE7
 try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); //new version of IE
 } catch (e1) {
  try {
   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //old version of IE
   
  } catch (e2) {
   xmlHttp = false;
  }
 }
}
  return xmlHttp;
    }
   /**
   * 
   */
function AllAreaWord(id)
 {
 //window.clipboardData.setData("Text",document.all('tableExcel').outerHTML);
try
{
 var oWD = new ActiveXObject("Word.Application");
 var oDC = oWD.Documents.Add("",0,1);
 var oRange =oDC.Range(0,1);
 var sel = document.body.createTextRange();
 var tableExcel=document.getElementById(id);
 tableExcel.style.border=0;
 sel.moveToElementText(tableExcel);
 sel.select();
 sel.execCommand("Copy");
 sel.moveEnd('character');   
 oWD.Application.Visible = true;
}
catch(e)
{
alert("您的电脑没有安装Microsoft Excel软件!"+e)
return false;
}
  oRange.Paste();
  oWD.ActiveWindow.ActivePane.View.Type=9;
}
/**
*方法作用:调用常用意见列表,将选择的意见返写到页面的指定输入框中
*/
function changeSms(node) 
{
if(node.checked)
document.getElementById("smsflag").value = node.value;
}
/**
*方法作用:调用常用意见列表,将选择的意见返写到页面的指定输入框中
*/
function visitorsbook(basePath,DealOpinion,flowkind_seqcode) 
{
htmlurl = basePath + "system/visitor/visitorsbook_Choose.action?officialKind="+flowkind_seqcode;
values = window.showModalDialog(htmlurl,'','dialogWidth=600px;dialogHeight=500px;dialogLeft=300px;dialogTop=200px;directories:no; localtion:no; menubar:no; status=no; toolbar=no;scrollbars:no;Resizeable=no;scroll:yes');
if(values)
DealOpinion.value = DealOpinion.value+values;
}
/**
* 方法作用:打印预览
** 参数:将要打印的内容通过 <span id="dayin"></span>包含起来,然后在某个按扭中定义事件
* 例:<input type="button" οnclick="prn1_preview(docid)" value="打印预览">
*/
function prn1_preview(docid) 
{
CreateOneFormPage(docid);
LODOP.PREVIEW();
};
/**
* 方法作用:直接打印
** 参数:将要打印的内容通过 <span id="dayin"></span>包含起来,然后在某个按扭中定义事件
*/
function prn1_print(docid) {
CreateOneFormPage(docid);
LODOP.PRINT();
};
function CreateOneFormPage(docid)
{
LODOP.ADD_PRINT_HTML(200,0,800,800,document.getElementById(docid).innerHTML);
};
/**
* 方法作用:将id为dayin的内容,新建页面并打印,可解决打印某页面中的部分内容的问题。
** 参数:将要打印的内容通过 <span id="dayin"></span>包含起来,然后在某个按扭中定义事件
* 例:<input type="button" οnclick="dayin()" value="打印">
*/
function dayin() 
{
var code="<body οnlοad=window.print()>"
code+=document.all.dayin.innerHTML;
code=code.toUpperCase();
code=code.replace(/<A[^>]*>删除<\/A>/gi, "");
code=code.toLowerCase();
var newwin=window.open('','','');
newwin.opener = null;
newwin.document.write(code);
newwin.document.close();
}


/**
* 方法作用:下载文件
** 参数:
*/
 function downloadFile(basePath,FileName,online_name,fileurl) 

window.location.href=basePath+"/downloads/download.action?filename="+FileName+"&filecode="+online_name+"&foldcode="+fileurl;
}
/**
* 方法作用:文件上传后,报错信息提示
*/
 function callback(msg) 

//document.getElementById("file").outerHTML = document.getElementById("file").outerHTML; 
document.getElementById("msg").innerHTML = "<font color=red>"+msg+"</font>"; 

/**
* 方法作用:文件上传后调用函数,返回上传文件信息到页面
* 参数说明:FileName:文件名称
*         online_name:服务器端文件名称;
*         fileurl:文件上传路径;
*         filesize:文件大小;
*         filekind:文件所属模块类型;
*/
function showInfo(FileName,online_name,fileurl,filesize,filekind)
{       
       //upload_frame.document.getElementById("file1").value="";
       //var   elm = thead_file.lastChild.cloneNode(true);
       
       var attChilds = thead_file.childNodes; 
var i = 0; 
while(attChilds[i].nodeType!=1 && i<=attChilds.length){ 
i++; 

elm = attChilds[i].cloneNode(true); 
  elm.style.display="";
var len1=tbody_file.rows.length;
//alert(len1);
tbody_file.appendChild(elm);
tbody_file.rows[len1].cells[1].innerHTML=len1+1;
tbody_file.rows[len1].cells[2].firstChild.value=FileName;  
tbody_file.rows[len1].cells[3].firstChild.value=online_name;
tbody_file.rows[len1].cells[4].firstChild.value=filesize;
tbody_file.rows[len1].cells[5].firstChild.value=fileurl;
tbody_file.rows[len1].cells[6].firstChild.value=filekind; 
try{
if(arguments[5]){
tbody_file.rows[len1].cells[8].firstChild.value=arguments[5]; 
//tbody_file.rows[len1].getElementByName("attcType")[0].value=arguments[5];
}
}catch(e){}
        document.getElementById("filelist").style.display="block";
}
/**
* 方法作用:文件上传后调用函数,返回上传文件信息到页面(传用于公文模板)
* 参数说明:FileName:文件名称
*         online_name:服务器端文件名称;
*         fileurl:文件上传路径;
*         filesize:文件大小;
*         filekind:文件所属模块类型;
*/
function showInfo_official(FileName,online_name,fileurl,filesize,filekind)
{       
      
        document.getElementById("filename").value=FileName;
        document.getElementById("uploadfilename").value=online_name;
        document.getElementById("filepath").value=fileurl;
        document.getElementById("filesize").value=filesize;
         //文件类型
         var filetypenum = FileName.lastIndexOf(".")
         var filetype = FileName.substring(filetypenum);
         document.getElementById("filetype").value=filetype;

/**
* 方法作用:删除页面中tbody中的信息,并将第二列显示序号重新排序
* 参数说明:tbody1:页面中tbody的id
*/
 function deleteRoleLine(tbody1)
 {


var tbody_jsp=document.getElementById(tbody1);
for(var i=tbody_jsp.children.length-1;i>=0;i--)
{
if (tbody_jsp.rows[i].cells[0].lastChild.checked)
{
tbody_jsp.deleteRow(i);
}
  }
  for (var i=0;i<tbody_jsp.children.length; i++)
{
tbody_jsp.rows[i].cells[1].innerHTML=i+1;
  }
 }
/**
* 方法作用:弹出窗口(不显示工具栏,地址栏,菜单栏)
* 参数说明:htmlurl:弹出窗口地址
*         wid:弹出窗口宽度
*         heig:弹出窗口高度
*/
function popWindowCenterNormal(htmlurl,wid,heig)
{
scWidth=screen.Width/2-wid/2;
scHeight=screen.Height/2-heig/2;
window.open(htmlurl,"","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,"+",left="+scWidth+",top="+scHeight+",width="+wid+",height="+heig);
}
/**
* 方法作用:判断数字,字母,中文
* 参数说明:表单输入 name为要显示的文字,value为页面输入值
*/
function checkNLC(name,value){
var reg = /^(\w|[\u4E00-\u9FA5])*$/;
if(arr=value.match(reg))
{
ti=1;
return ture;
}
else
{
alert(name+"只允许为英文,数字和汉字的混合!");
ti=0;
return false;
}
}
/**
* 方法作用:判断不允许有汉字与字母
* 参数说明:表单输入
*/
function checkChOrEn(name,value){
if(/[^\x00-\x80]/ig.test(value)){
alert(name+"不允许有汉字!");
return false;
}
if(isNaN(value)){
alert(name+"不允许有字母!");
return false;
}
return true;
}
/**
* 方法作用:判断不允许有汉字
* 参数说明:表单输入
*/
function checkchina(name,value){
if(/[^\x00-\x80]/ig.test(value)){
alert(name+"不允许有汉字");
return false;
}
return true;
}
/**
* 方法作用:判断只能是英文和数字的函数
* 参数说明:表单输入
*/
function checkNum(name,value){
var str = /[_a-zA-Z]/;
if(!str.test(value)){
alert(name+"只允许为字母!");
return false;
}else{
return true;
}
}
/**
* 方法作用:判断只能是数字的函数
* 参数说明:表单输入
*/
function isNumber(name,value){
  isNum = /^[0-9]*$/;
if(isNum.test(value)){
return true;

}else{
alert(name+"只允许为数字,请修改!");
return false;
}
}
/**
* 方法作用:判断只能是英文和数字的函数
* 参数说明:表单输入
*/
function isEnOrNumber(name,value){
  var str =  /^\w+$/;
if(str.test(value)){
return true;

}else{
alert(name+"只允许为数字或英文字母");
return false;
}
}
/**
* 方法作用:判断只能是汉字
* 参数说明:表单输入
*/
function isChina(name,value){
  var str =  /[^\u4E00-\u9FA5]/g;
if(str.test(value)){
alert(name+"只允许为汉字");
return false;

}else{
return true;
}
}
/**
* 方法作用:js判断为空
* 参数说明:表单输入
*/
function checkNull(name,value){
if(value=="")
{
alert("请填写"+name);
return false;
}else{
return true;
}
}
//出现汉字的字符长度校验
function GetLen(name,value,lenght) {
 var len=0; 
 for(var i=0;i<value.length;i++) {
    char = str.charCodeAt(i);    
    if(!(char>255)) {
    len = len + 1;  
    }else{
    len =len + 2;
    }
   }
  
   if(len>lenght){
    alert(name+"长度不能大于"+lenght);
return false;
   }
    return true; 



/**
* 方法作用:js判断长度
* 参数说明:表单输入
*/
function checkLength(name,value,len){
if(value.length>len)
{
alert(name+"长度不能大于"+len);
return false;
}else
{
   return true;
}
return true;
}
/**
* 方法作用:js判断长度范围
* 参数说明:表单输入
*/
function checkLengthFW(name,value,low,hight){
if(value.length<low)
{
alert(name+"长度不能小于"+low);
return false;
}else if(value.length>hight)
{
   alert(name+"长度不能大于"+hight);
return false;
}
return true;
}
/**
* 方法作用:判断数字
* 参数说明:表单输入
*/
function checkOnlyNum(name,value)
{
for(var i=0;i<value.length;i++)
    {
        if(value.charCodeAt(i)<48||value.charCodeAt(i)>57)
        {
        alert(name+"只能是数字!");
            return false;
            break;
        }
    }
    return true;
}
/**
* 方法作用:判断数字最大长度
* 参数说明:表单输入
*/
function checkNumLength(name,value,len)
{
if(value.length>len)
{
alert(name+"长度不能大于"+len);
return false;
}
for(var i=0;i<value.length;i++)
    {
        if(value.charCodeAt(i)<48||value.charCodeAt(i)>57)
        {
        alert(name+"只能是数字!");
            return false;
            break;
        }
    }
    return true;
}
/**
* 方法作用:判断数字是否是数字(可包含两位小数)
* 参数说明:表单输入
*/
function isMoney(name,value){
 var patrn=/^((-){0,1})(\d)*(\.(\d){0,2})?$/;
 if(patrn.exec(value)==null){
  alert(name+"必须是数值,可包括2位小数");
  return false;
 }


 return true;
}
/**
* 方法作用:判断数字是否是数字(可包含多个小数点)
* 参数说明:复选框表单名称
*/
function checkFloat(name,value) 

    var regstr = /[^0-9.]/gi; 
    if (regstr.exec(value) != null) 
    { 
       alert(name+"必须是数值,同时可以为小数!");
  return false;
    } 
    return true;

/**
* 方法作用:判断checkbox是否有一个被选中 
* 参数说明:复选框表单名称
*/
function  checkCheckbox(checkboxname)   
{   
      var ss=0;
      var aa =document.getElementsByName(checkboxname);   
      for(var i=0;i<aa.length;i++)   
      {   
          if(aa[i].checked){
         ss++;
          }
    
      }  
      if(ss==0){ 
      alert("很抱歉,请至少要选择一条需要操作的信息!");  
  return false;}
 else{
  return true;
 }  
}
/**
* 方法作用:全选checkbox
* 参数说明:复选框表单名称
*/
function  checkAll(checkall,checkboxname)   
{   
      var aa =document.getElementsByName(checkboxname);   
      for(var i=0;i<aa.length;i++)   
      {   
          aa[i].checked=checkall.checked;
    
      }  
}
/**
* 方法作用:测试是否为数字
* 参数说明:表单输入
*/
function isNum(value) {
var trueORtel1;
var pattern = /^([0-9.]){1,}$/;
trueORtel1 = pattern.test(value);
return trueORtel1;
}
/**
* 方法作用:测试传真格式
* 参数说明:表单输入
*/
function isFax(value) {
var trueORtel1;
var pattern =  /^([0-9])+-([0-9])+/; 
trueORtel1 = pattern.test(value);
return trueORtel1;
}
/**
* 方法作用:测试电子邮件格式
* 参数说明:表单输入
*/
function isEmail(value) {
var trueORtel1;
var pattern =  /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
trueORtel1 = pattern.test(value);
return trueORtel1;
}
/**
* 方法作用:测试时间格式是否为yyyy-mm-dd
* 参数说明:表单输入
*/
function  checkdate(time1)
{  
     if(isInvalidDate(time1,'-')==true)
     {  
      alert("请正确正确的日期格式(例如:1981-11-12)!");  
      return  false;
      } 
     else {return true;} 
}
/**
* 方法作用:设置失效
* 参数说明:表单
*/
function setdisabled(button)
{
var objbutton = button;
objbutton.disabled ==true;
}
/**
* 方法作用:时间比较方法
* 参数说明:字符类型,
* 时间格式:yyyy-mm-dd 或yyyy-mm-dd hh:mm:ss
* 结果:当time1大于time2时返回false,否则返回true;
*/
function CompareTime(time1,time2)
{
if(time1!="" && time2!="")
{
      if(time1.length>=10&&time1.length<16)
      {
      var time1= time1.substring(0,10);
      }
      else if(time1.length>=16&&time1.length<19)
      {
      var time1= time1.substring(0,16);
      }
      else if(time1.length>=19)
      {
      var time1= time1.substring(0,19);
      }
       if(time2.length>=10&&time2.length<16)
      {
      var time2= time2.substring(0,10);
      }
      else if(time2.length>=16&&time2.length<19)
      {
      var time2= time2.substring(0,16);
      }
      else if(time2.length>=19)
      {
      var time2= time2.substring(0,19);
      }
     // alert(time1);alert(time2);
    if((new Date(time1.replace(/-/g,"\/"))) > (new Date( time2.replace(/-/g,"\/"))))
    {
    return false;
    }
    else
     {
  return true;
       }

else {return false;}
}
/**
* 加载页面时控制页面显示不全的处理
* 一般在body中掉用:例<body οnlοad="resizeIframe()">
*/
function resizeIframe(win)
{
if(win == null){
window.setTimeout('doResize()', 100);
}
else{
doResize(win);
}
}


function doResize(win)
{
if(win == null)
win = window;
parentWin = win.parent;
//if(parentWin != null && "WebRoot/js/CompareTime.js"win.name.length != 0 && parentWin.frames.length > 0)
if(win != window.top && parentWin.frames.length > 0)
{
myframe = parentWin.document.getElementById(win.name);
  //myframe = $(parentWin.document).find(win.name);
iHeight = win.document.body.scrollHeight;//offsetHeight;
myframe.style.height = iHeight+ "px";


resizeIframe(parentWin);
}
}
/**
* 加载页面时控制页面显示不全的处理
* 一般在body中掉用:例<body οnlοad="resizeIframe()">
*/
function resizeIframeFile(win)
{
if(win == null){
window.setTimeout('doResizeFile()', 100);
}
else{
doResizeFile(win);
}
}


function doResizeFile(win)
{
if(win == null)
win = window;
parentWin = win.parent;
//if(parentWin != null && "WebRoot/js/CompareTime.js"win.name.length != 0 && parentWin.frames.length > 0)
if(win != window.top && parentWin.frames.length > 0)
{
//myframe = parentWin.document.getElementById(win.name);
//myframe = parentWin.frames[2];
myframe = parentWin.document.getElementById(win.name);
//iHeight = win.document.documentElement.scrollHeight;//offsetHeight;
myframe.style.height = 110+ "px";
resizeIframeFile(parentWin);
}

function forIdCard(C) {
var F = new Array(
"",
"号码位数不对!",
"号码出生日期超出范围或含有非法字符!",
"号码校验错误!",
"地区非法!"), G, E, _, $, B, A = C.v_name;
if (A == null)
A = "";
var G = C, D = new Array();
D = G.split("");
switch (G.length) {
case 15:
if ((parseInt(G.substr(6, 2)) + 1900) % 4 == 0
|| ((parseInt(G.substr(6, 2)) + 1900) % 100 == 0 && (parseInt(G
.substr(6, 2)) + 1900) % 4 == 0))
ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;
else
ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;
if (ereg.test(G))
return true;
else {
//alert(A + F[2]);
return false
}
break;
case 18:
if (parseInt(G.substr(6, 4)) % 4 == 0
|| (parseInt(G.substr(6, 4)) % 100 == 0 && parseInt(G.substr(6,
4)) % 4 == 0))
ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;
else
ereg = /^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;
if (ereg.test(G)) {
$ = (parseInt(D[0]) + parseInt(D[10])) * 7
+ (parseInt(D[1]) + parseInt(D[11])) * 9
+ (parseInt(D[2]) + parseInt(D[12])) * 10
+ (parseInt(D[3]) + parseInt(D[13])) * 5
+ (parseInt(D[4]) + parseInt(D[14])) * 8
+ (parseInt(D[5]) + parseInt(D[15])) * 4
+ (parseInt(D[6]) + parseInt(D[16])) * 2 + parseInt(D[7])
* 1 + parseInt(D[8]) * 6 + parseInt(D[9]) * 3;
E = $ % 11;
B = "F";
_ = "10X98765432";
B = _.substr(E, 1);
if (D[17] == "x")
D[17] = "X";
if (B == D[17])
return true;
else {
//alert(A + F[3]);
return false
}
} else{
//alert(A + F[2]);
}
return false;
break;
default:
//alert(A + F[1]);
return false
}
}
//验证身份证号
function checkSfzs(Obj,name){
var sfzh=Obj.value;
if(!forIdCard(sfzh)){
    alert("对不起,"+name+"格式不对,请重新输入。");
      Obj.value='';
      Obj.focus();

}
//验证邮箱号
function CheckEmail(Obj,name){
if(!isEmail(Obj.value)){
  alert("对不起,"+name+"格式不对,请重新输入。");
      Obj.value='';
      Obj.focus();
}
}
//验证联系电话
function CheckPhone(Obj,name){
if(Obj.value!=''&&Obj.value!=null){
if(!(/(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/.test(Obj.value))){
if(!(/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}13[0-9]{9}$)/.test(Obj.value))){
alert(name+"格式不对,请重新输入。");
Obj.value='';
Obj.focus();
return false;
}
}
}
}
//判断是否为金额
function CheckMoney(Obj,name){
if(!isMoney(name,Obj.value)){
      Obj.value='';
      Obj.focus();
}
}
//判断是否为邮编
function CheckYb(Obj,name){
if(!checkOnlyNum(name,Obj.value)){
//alert(name+"格式不对,请重新输入。");
Obj.value='';
      Obj.focus();
}
}
//判断是否为整数或者为小数
function CheckNumber(Obj,name){
if(!checkFloat(name,Obj.value)){
//alert(name+"格式不对,请重新输入。");
Obj.value='';
       Obj.focus();
}
}
//判断是否为字母
function checkNumber(Obj,name){
if(!checkNum(name,Obj.value)){
Obj.value='';
       Obj.focus();
}
}


function SetCwinHeight(obj){ 
  if (document.getElementById){ 
   if (obj && !window.opera){ 
    if (obj.contentDocument && obj.contentDocument.body.offsetHeight){ 
     obj.height = obj.contentDocument.body.offsetHeight; 
    }else if(obj.Document && obj.Document.body.scrollHeight){ 
     obj.height = obj.Document.body.scrollHeight; 
    } 
   } 
  } 
 }
 //小写转成大写金额
function AmountLtoU(num){
  var strOutput = "";
  var strUnit = '仟佰拾亿仟佰拾万仟佰拾元角分';
  num += "00";
  var intPos = num.indexOf('.');
  if (intPos >= 0)
    num = num.substring(0, intPos) + num.substr(intPos + 1, 2);
  strUnit = strUnit.substr(strUnit.length - num.length);
  for (var i=0; i < num.length; i++)
    strOutput += '零壹贰叁肆伍陆柒捌玖'.substr(num.substr(i,1),1) + strUnit.substr(i,1);
    return strOutput.replace(/零角零分$/, '整').replace(/零[仟佰拾]/g, '零').replace(/零{2,}/g, '零').replace(/零([亿|万])/g, '$1').replace(/零+元/, '元').replace(/亿零{0,3}万/, '亿').replace(/^元/, "零元");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值