You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于登录系统邮箱验证误将.info域名标记为无效的技术求助

Fix for .info Email Validation Issue

Hey there! I spot the problem immediately—your email validation regex is restricting top-level domains (TLDs) to only 2-3 characters, which is why .info (a 4-character TLD) is getting incorrectly marked as invalid. Let's break this down and fix it step by step.

The Root Cause

Your validation regex includes this segment:

(\.\w{2,3})+

The {2,3} quantifier limits the length of the TLD to 2 or 3 characters. But modern TLDs like .info, .club, and .online are 4+ characters long, so they fail to match this pattern.

Fixed Validation Code

Update the regex to allow longer TLDs (I’ve set it to up to 6 characters, which covers most common TLDs including newer ones):

$('#email').keyup(function () {
  if ($("#email").val().match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/)) {
    $("#emailmessage").html('Email is valid!');
  } else {
    $("#emailmessage").html('This is invalid email!');
  }
});

If you want full compliance with ICANN rules (which allow TLDs up to 63 characters), you can adjust the quantifier to {2,63} instead:

/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,63})+$/

Bonus Fix: Onkeypress Event Syntax Error

Your onkeypress attribute has a syntax bug—the comma operator you’re using doesn’t actually enforce the space-blocking logic. Update it to properly check for space key presses:

<input 
  type="email" 
  placeholder="E-mail..." 
  id="email" 
  name="email" 
  onkeypress="return (event.keyCode !== 32 && event.which !== 32);" 
  onpaste="return false;"
>
<div class="message" id="emailmessage"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

Quick Notes

  • The type="email" attribute already provides basic browser-level validation, so make sure your custom regex aligns with that behavior.
  • Disabling paste might frustrate some users (e.g., those who want to paste a saved email address), but that’s a call you can make based on your specific use case.

内容的提问来源于stack exchange,提问作者popov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 00:12:35