微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

正则表达

<!DOCTYPE html>
<html>
<head>
 <title>正则表达式</title>
 <Meta charset="utf-8">
 <style>
 .input{
            width: 300px;
            height: 40px;
            font: 20px/40px "";
            margin: 200px 320px;
        }
        .input1{
         
            height: 40px;
            font: 20px/40px "";
            margin: 200px -320px;
        }
    .a{
             width: 120px;
             height: 50px;
             position: relative;
             left: 300px;
             font: 30px/50px "";
         }
    </style>
    <script>
    function 检测()
 {
  var name=document.getElementsByTagName(‘name‘).value;
  var norms=/^[A-Za-z0-9]{1,6}/;
  
  if (norms.test(name))
  {
   alert("OK");
  }
  else
  {
   alert("NO");
  }
 }
 </script> 
 
</head>
<body>
 <label for="name" class="a">Name:</label>
  <input type="text" placeholder="不超过6个字符" name="name" id="name" class="input">
  <input type="button" value="检测" onclick="检测()" class="input1">
 
 
</body>
</html>
 
效果如下:

分享图片

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐