gpt4 book ai didi

javascript - 我无法使用 Javascript 验证验证码是否错误

转载 作者:行者123 更新时间:2023-11-28 04:59:06 24 4
gpt4 key购买 nike

这是 JavaScript

<script>
function q_form_val() {
var patt = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var captcha_entered = document.getElementById("captcha_entered").value;
if (captcha_entered == "") {
alert("Please enter the Captcha");
return false;
}
return true;
}
</script>

这是 HTML 代码

<div class="row">
<div class="form-group">
<label class="control-label col-sm-3"><font color="#FF0000">*</font><strong>Captcha</strong>
</label>
<div class="col-sm-3">
<?php echo '<img src="captcha.php" alt="captcha">'; ?>
<br/>
<span><input name="captcha_entered" type="text" class="form-control" id="captcha_entered" size="27" maxlength="4"/></br></span>
<input type="hidden" name="captcha_total" id="captcha_total" value="<?php echo $_SESSION['rand_code']; ?>">
</div>
</div>
</div>
<div>&nbsp;</div>
<div class="row">
<div class="col-sm-12">
<center>
<script type="text/javascript">
document.write("<input type=\"submit\" value=\"Submit\" class=\"btn1\"/>");
</script>
<noscript>
<p style="color: red;"><b><i>Please enable JavaScript to continue</i></b>
<p>
</noscript>
</center>
</div>
</div>

我可以检查验证码是否为空但我无法检查验证码是错误还是正确我想我应该在 javascript 中添加更多代码来验证它是错误还是正确?

最佳答案

问题是您是否应该使用Javascript验证验证码。验证码的全部目的是规避自动脚本,但在 HTML 中包含答案使其非常容易被绕过。

您应该通过表单提交或 AJAX 请求来验证服务器上的验证码。

关于javascript - 我无法使用 Javascript 验证验证码是否错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42311648/

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