当前位置:   article > 正文

js正则表达式提取邮箱并复制到粘贴板

js正则表达式提取邮箱并复制到粘贴板
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Email Extractor</title>
  <style>
    .container {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-top: 20px;
    }

    .input-group, .output-group {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
    }

    textarea {
      margin-right: 10px;
      padding: 10px;
      border: 1px solid #ccc;
      border-radius: 5px;
    }

    .btn {
      padding: 10px 20px;
      border: none;
      border-radius: 5px;
      cursor: pointer;
    }

    .btn-primary {
      background-color: #007bff;
      color: white;
    }

    .btn-secondary {
      background-color: #6c757d;
      color: white;
    }

    .btn-success {
      background-color: #28a745;
      color: white;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="input-group">
      <textarea id="input" rows="5" cols="50" placeholder="Enter text here..."></textarea>
      <button onclick="extractEmails()" class="btn btn-primary">Submit</button>
      <button onclick="clearInput()" class="btn btn-secondary">Clear</button>
    </div>

    <div class="output-group">
      <h2>Extracted Email Addresses:</h2>
      <textarea id="output" rows="5" cols="50" readonly></textarea>
      <button onclick="copyOutput()" class="btn btn-success">Copy</button>
    </div>
  </div>

  <script>
    async function extractEmails() {
      let inputText = document.getElementById("input").value;
      let emails = inputText.match(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g);
      document.getElementById("output").value = JSON.stringify(emails);

      // 提取电子邮件地址后自动复制到粘贴板
      let outputText = document.getElementById("output").value;
      await navigator.clipboard.writeText(outputText);
<!--      alert("Copied to clipboard!");-->
    }

    function clearInput() {
      document.getElementById("input").value = "";
      document.getElementById("output").value = "";
    }
  </script>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/559727
推荐阅读
相关标签
  

闽ICP备14008679号