1yuruyi
在JS中使用正则表达式验证电子邮箱
<input type="text" id="email" name="email">
<input type="button" value="验证" onclick="isEmail(\'email\')">
   <script language="javascript">
function isEmail(email) {
var strEmail=document.getElementById(email).value;
   if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
{
   alert("Email格式正确!");
   return true;
   }else{
     alert("Email格式不正确!");
     document.getElementById(email).value="";
     document.getElementById(email).focus();
     return false;
    }
}
</script>

分类:

技术点:

相关文章:

  • 2021-11-23
  • 2022-01-07
  • 2021-07-08
  • 2021-12-23
猜你喜欢
  • 2021-07-31
  • 2021-12-03
  • 2021-11-21
  • 2021-12-22
  • 2021-12-03
  • 2021-12-03
  • 2021-12-03
相关资源
相似解决方案