分享

V2.7字符串实例--邮箱验证.htm

 时间剧毒 2015-07-11

<!Doctype html>
<html xmlns="http://www./1999/xhtml">
<head>
    <title>字符串实例</title>
     <style type="text/css">
      #show{
            width:200px;
            height:200px;
            margin:0 auto;
            color:white;
            background:#2c2c2c;
            text-align:center
           }

      </style>

   <script type="text/javascript">
   //字符串实例: 邮箱验证
function check(){
                  var obj= document.getElementById("email") //得到元素 通过id 获得
                  //值  alert(obj.value) //值
             if (obj.value!=""){
                            var str =obj.value
                            if (str.indexOf("@")!=-1){
                                        if (str.indexOf(".")!=-1){
                                                                   var a =str.split("@")   //拆分成数字
                                                                   if(a[0].length>1){
                                                                                      document.getElementById ("mess").innerHTML="<font color='green'>正确</font>" 
                                                                                    
                                                                   }else{
                                                                          document.getElementById ("mess").innerHTML="<font color='red'>@长度错误</font>" 
                                                                                    
                                                                          }
                                         
                                            
                                        }else{
                                               document.getElementById ("mess").innerHTML="<font color='red'>没有.错误</font>"   //没有

                                             }

                            }else{
                                //  document.getElementById ("mess").innerText="<font color='red'>错误</font>"   //没有Value  innerText内部文本
                                   document.getElementById ("mess").innerHTML="<font color='red'>错误</font>"   //没有
                                 }
                                
              }
}
  
  
     

   </script>


</head>

<body>

<label>email:</label><input type="text" id="email"/>

<input type ="button" value="验证" onclick ="check()"/>

<span id="mess"></span>


</body>


</html>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多