常用js函数CheckData.js

 
/*------------------------------------------------------------
  自定义内容对话框显示
  隐藏对话框:HideDLG(ControlID)
  ------------------------------------------------------------*/
function ShowDialog(ControlID)
{
    var width = document.getElementById(ControlID).style.width;
    var height = document.getElementById(ControlID).style.height;
    width = width.substr(0,width.length - 2);
    height = height.substr(0,height.length - 2);
    document.getElementById(ControlID).style.left=((screen.width-width)/2) + "px";
    document.getElementById(ControlID).style.top=(screen.height/2-200) + "px";
    //document.getElementById(ControlID).style.top=screen.height/2-0;
    ShowDLG(ControlID);
}

/*------------------------------------------------------------
  文本提示内容对话框显示
  隐藏对话框:HideDLG(ControlID)
  ------------------------------------------------------------*/
function ShowMessage(ControlID,strMessage)
{
    document.getElementById(ControlID).style.left=screen.width/2-100 + "px";
    document.getElementById(ControlID).style.top=(screen.height/2-200 + document.documentElement.scrollTop)  + "px";
    document.getElementById("DialogMessage").innerHTML=strMessage;
    ShowDLG(ControlID);
}
/*------------------------------------------------------------
    显示带遮罩的对话框
-/**//*------------------------------------------------------------
增加一个半透明的遮罩
注:(宽高为自适应屏幕)  HidShieldDiv(隐藏)
-----------------------------------------------------------------*/

function ShowShieldDiv(ControlID,strMessage)
{
    ShowMessage(ControlID,strMessage);
    window.setTimeout("addDivControl()",50);
}


function addDivControl()
{
     if( document.getElementById("shieldDiv"))
        {
              document.getElementById("shieldDiv").style.display=""; 
        }
        else
        {
            var shield = document.createElement("DIV");
                shield.id = "shieldDiv";
                shield.style.position = "absolute";
                shield.style.left = "0px";
                shield.style.top = "0px";
                shield.style.width = "100%";
                shield.style.height = ((document.documentElement.clientHeight>document.documentElement.scrollHeight)?document.documentElement.clientHeight:document.documentElement.scrollHeight)+"px";
                shield.style.background = "#000000";
                shield.style.textAlign = "center";
                shield.style.zIndex =  "999";
                if (document.all)
                {
                    shield.style.filter = "alpha(opacity=20)";
                }
                else
                {
                    shield.style.opacity =  0.20;
                }
              document.body.appendChild(shield);
         }
   
}
/*------------------------------------------------------------
隐藏遮罩对话框

-----------------------------------------------------------------*/
function HidShieldDiv(ControlID)
{
     if ( document.getElementById("shieldDiv"))
      {
         document.getElementById("shieldDiv").style.display="none";
      }
      HideDLG(ControlID);
}

 
 

 

/*------------------------------------------------------------
  文本提示内容对话框显示
-------------------------------------------------------------*/
function ShowMessage1(strMessage)
{
    alert(strMessage);
   
   
   
}

/*------------------------------------------------------------
  验证输入的是否为数字
 使用例子onBlur="CheckIfNumerical(this)"
  ------------------------------------------------------------*/
function CheckIfNumerical(TextID)
{
 //var searchStr = /^(\-)?(0|[1-9](\d)*)(\.(\d)+)?$/    //这是判断是否为浮点型数字
 var searchStr = /^(\-)?(0|[1-9](\d)*)$/  //这是判断是否为整型数字

 if( !searchStr.test(document.getElementById(TextID).value) )
 {
  if(""==document.getElementById(TextID).value)
  {}
  else
  {
   document.getElementById(TextID).value="";
   alert("必须是数字!");
   document.getElementById(TextID).focus();
   return;
  }
 }
}

/*------------------------------------------------------------
  验证身份证号码
 使用例子onBlur="CheckIfidCard(this)"
  ------------------------------------------------------------*/
function CheckIfidCard(TextID)
{
 //var searchStr = /^(\-)?(0|[1-9](\d)*)(\.(\d)+)?$/    //这是判断是否为浮点型数字
 var searchStr = /^(\d{15}|\d{17}[\dXx])$/  //这是判断是否为整型数字

 if( !searchStr.test(TextID.value) )
 {
  if(""==TextID.value)
  {}
  else
  {
   TextID.value="";
   alert("身份证号码错误!");
   return;
  }
 }
}

/*------------------------------------------------------------
  验证电话号码
 使用例子onBlur="CheckTelephone(this)"
  ------------------------------------------------------------*/
function CheckTelephone(TextID)
{
 //var searchStr = /(?<GP1>((\(|()0([0-9]|[1-8]){2,3}(\)|)))|(0([0-9]|[1-8]){2,3})(\-)?)(?<GP2>([0-9]|[1-8]){7,8})/
 var searchStr = /(^\d{3,4}-\d{7,8}$)|(^13\d{9}$)/
 if( !searchStr.test(TextID.value) )
 {
  if(""==TextID.value)
  {}
  else
  {
   TextID.value = "";
   alert("电话号码格式错误,格式应为:010-12345678");
  }
 }
}

/*------------------------------------------------------------
 验证手机号码
 使用例子onBlur="CheckMobile(this)"
  ------------------------------------------------------------*/
function CheckMobile(TextID)
{
 var searchStr = /^13[0123456789]{1}\d{8}$/
 if( !searchStr.test(TextID.value) )
 {
  if(""==TextID.value)
  {}
  else
  {
   TextID.value = "";
   alert("手机号码格式错误,格式应为:13512345678");
  }
  
  return false;
 }
 
 return true;
}

/*------------------------------------------------------------
 验证邮政编码
 使用例子onBlur="CheckPostcode(this)"
  ------------------------------------------------------------*/
function CheckPostcode(TextID)
{
 var searchStr = /\d{6}/
 if( !searchStr.test(TextID.value) )
 {
  if(""==TextID.value)
  {}
  else
  {
   TextID.value = "";
   alert("邮编错误,格式应为:515063");
  }
 }
}
/*------------------------------------------------------------
 判断输入的是否为电子邮件,如含非法字符则提示
 text-------输入的电子邮件
 使用例子onBlur="IsEmail(this)"
  ------------------------------------------------------------*/
function IsEmail(text)
{  
 var email=text.value.Trim();
 var m=email.indexOf("@");
 var n=email.indexOf(".");
 if(email!="")
 {
  if(m<1||m>email.length-3)
  {
   alert("请输入正确的电子邮件格式!");
   text.focus();
   return false;
  }
  else if(n<m+2||n>email.length-2)
  {
   alert("请输入正确的电子邮件格式!");
   text.focus();
   return false;
  }
 }
}

/*------------------------------------------------------------
 判断输入的是否为电子邮件
------------------------------------------------------------*/
function CheckEmail(email)  
{
  if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
  { 
     alert("请输入正确的电子邮件格式!");
     return false;  
  }else{
     return true;
  }
}

/**//*------------------------------------------------------------
 Trim()去左右空格
  ------------------------------------------------------------*/

String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
    return this.replace(/(^\s*)/g, "");
}
String.prototype.Rtrim = function()
{
    return this.replace(/(\s*$)/g, "");
}

 

 


/**//*------------------------------------------------------------
 两个时间进行比较,当开始日期大于结束日期则提示
 startDate----开始日期
 endDate------结束日期
 使用例子onClick="CompareTwoDate(startDate,endDate,'开始日期不能大于结束日期!')"
  ------------------------------------------------------------*/
function CompareTwoDate(startDate,endDate,s)
{
var a=startDate.value;
var b=endDate.value;
if(((Number(a.substring(0,4))-Number(b.substring(0,4)))*356+
       (Number(a.substring(5,7))-Number(b.substring(5,7)))*31+
    (Number(a.substring(8,10))-Number(b.substring(8,10))))>0)
 {
  alert(s);
  startDate.focus();
 }
}

/**//*------------------------------------------------------------
 两个时间进行比较,当开始日期大于结束日期则提示
 startDate----开始日期
 endDate------结束日期
 使用例子 return CompareTwoDate(startDate,endDate)"
  ------------------------------------------------------------*/
function CompareDate(startDate,endDate)
{
    var a = startDate;
    var b = endDate;
    if(((Number(a.substring(0,4))-Number(b.substring(0,4)))*356+
    (Number(a.substring(5,7))-Number(b.substring(5,7)))*31+
    (Number(a.substring(8,10))-Number(b.substring(8,10))))>0)
    {
        return false;
    }
    else
    {
        return true;
    }
}
 
 
 

 

/**//*------------------------------------------------------------
 检查用户登陆输入是否齐全
 objAccount----帐号文本框
 objPassword----密码文本框
 objCode----验证码文本框
 使用例子onClick="CheckUserInput(txtaccount,txtpswd,txtcode)"
  ------------------------------------------------------------*/
function CheckUserInput(objAccount,objPassword,objCode)
{
    if(document.getElementById(objAccount).value=="")
    {
        document.getElementById(objAccount).style.border="solid 1px #FF0000";
        document.getElementById(objAccount).focus();
        return false;
    }
    else
    {
        document.getElementById(objAccount).style.border="solid 1px #000000";
        if(document.getElementById(objPassword).value=="")
        {
            document.getElementById(objPassword).style.border="solid 1px #FF0000";
            document.getElementById(objPassword).focus();
            return false;
        }
        else
        {      
            document.getElementById(objAccount).style.border="solid 1px #000000";       
            document.getElementById(objPassword).style.border="solid 1px #000000";
            if(document.getElementById(objCode).value=="")
            {
                document.getElementById(objCode).style.border="solid 1px #FF0000";
                document.getElementById(objCode).focus();
                return false;
            }
        }
    }
    return true;
}

转载请注明出处:http://blog.csdn.net/dasihg/article/details/6794700

转载于:https://www.cnblogs.com/dashi/archive/2011/09/20/4034776.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值