gpt4 book ai didi

javascript - 电子邮件地址验证但创建帐户,但如果电子邮件地址无效

转载 作者:行者123 更新时间:2023-11-28 00:26:51 26 4
gpt4 key购买 nike

我编写了用于电子邮件地址验证的脚本,如果提供了无效的电子邮件,它会发出警报通知。尽管该帐户是使用相同的无效电子邮件地址创建并存储在数据库中...请帮助代码似乎是:

    <div class="form">

<ul class="tab-group">
<li class="tab "><a href="#signup">Sign Up</a></li>
</ul>

<div class="tab-content">


<form name="form1" action="trynow" method="post" onsubmit="ValidateEmail(document.form1.txtEmail)">
<div>
<input type="hidden" name="register_csrf" autocomplete="false" autofocus="false" value="<%=((String)request.getAttribute("register_csrf")!=null)?request.getAttribute("register_csrf"):"" %>"/>

<% String error_msg = (String)request.getAttribute("error_msg");
if(error_msg != null)
{
%>
<div class="alert alert-error"> <%= error_msg %></div>

<% } %>
<%= ((String)request.getAttribute("succ_msg") != null)?request.getAttribute("succ_msg"):"" %>

</div>



<div class="field-wrap">
<label>
Full Name<span class="req">*</span>
</label>
<input required="required" name="txtName" type="text" >
</div>



<div class="field-wrap">
<label>
Email Address<span class="req">*</span>
</label>
<input required="required" name="txtEmail" type="text" >
</div>

<div class="field-wrap">
<label>
Set A Password<span class="req">*</span>
</label>
<input name="txtPassword" type="password" >
</div>

<div class="field-wrap">
<label>
Retype Password<span class="req">*</span>
</label>
<input name="txtRePassword" type="password" >
</div>
<div>
<button type="submit" class="button button-block" />Get Started</button>
</div>
<a class="small-message" href="login"><small>Already Registered ?</small></a><a href="/"> <small> <br>Back To Home</small></a>
</form>
<script>
function ValidateEmail(inputText)
{
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(inputText.value.match(mailformat))
{
document.form1.txtEmail.focus();
return true;
}
else
{
alert("You have entered an invalid email address!");
document.form1.text1.focus();
return false;
}
}
</script>

</div><!-- tab-content -->

</div> <!-- /form -->

最佳答案

在提交表单时,使用return ValidateEmail(this.txtEmail)"

<form name="form1" action="trynow" method="post" onsubmit="return ValidateEmail(this.txtEmail)">

现在,只有当电子邮件有效时,表单才会提交。否则就会被阻止。

此外,您还引用了 document.form1.text1.focus();,而 text1 根本不存在于表单中。所以你在这里也一定会遇到错误。

关于javascript - 电子邮件地址验证但创建帐户,但如果电子邮件地址无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29405628/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com