这是我的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> </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
function q_form_val() {
var patt = new RegExp(/^\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;
}else if(!patt.test(captcha_entered)){
alert("Bad Captcha Match");
return false;
}
return true;
}对于正确的验证码和错误的验证码,它也会显示相同的弹出消息。错误和正确的验证码显示与错误验证码相同的错误。
右验证码的问题是什么?验证的问题是什么?
发布于 2017-02-18 20:46:15
从这里得到帮助。它会解决你的问题。明智地使用它
<?php session_start();
$_SESSION['code'] = '1323'; // here will your captcha is stored i have used a constant value;
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form>
<input type="text" name="captcha" id="captcha">
<input type="submit" name="submit" value="submit" onclick=" event.preventDefault(); q_form_val();">
</form>
<script>
function q_form_val() {
var captcha_entered = document.getElementById("captcha").value;
if (captcha_entered == "") {
alert("Please enter the Captcha");
return false;
}else if( captcha_entered == "<?php echo $_SESSION['code']; ?>" ){
alert("captcha matched");
return true;
}else if( captcha_entered != "<?php echo $_SESSION['code']; ?>" ){
alert("captcha not matched");
return false;
}
}
</script>
</body>
</html>https://stackoverflow.com/questions/42313552
复制相似问题