使用Jquery Validate插件,是否有一種方法,只要第一個鍵被按下,並顯示錯誤消息,直到他們已經輸入需要什麼爲止?Jquery驗證插件Keydown
所以在輸入字段我希望出現確認消息,直到它們正確地輸入需要什麼第一次按鍵
我的代碼如下
<?php
// Error Config
include_once("PHP/Config.php");
// Session
include_once("PHP/Session.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>TBA </title>
<meta name="description" content="Coming soon
<meta name="keywords" content="
" />
<link rel="icon" type="image/ico" href="favicon.ico"/>
<link href="CSS/Site_Style.css" rel="stylesheet" type="text/css" />
<link href="CSS/Register_Form.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="JS/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.validate.js"></script>
<script type="text/javascript" src="JS/additional-methods.min.js"></script>
<script>
$(document).ready(function() {
$("#SignUp").validate({
rules: {
email: {
required: true,
email: true
},
password: {
required: true,
password: true
},
confirm_password: {
required: true,
password: true,
notEqual: "#password"
},
company: {
nls: true,
required: true
},
telephone: {
phone: true
}
}
});
$.validator.addMethod("email", function (value, element) {
return this.optional(element) || /^[a-zA-Z0-9._-][email protected][a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/i.test(value);
}, "Please enter a valid email address");
$.validator.addMethod("password", function (value, element) {
return this.optional(element) || /^[[email protected]#$%^&*()_]{6,16}$/i.test(value);
}, "Passwords are 6-16 characters");
jQuery.validator.addMethod("notEqual", function (value, element, param) {
return this.optional(element) || value == param;
}, "Passwords Do Not Match");
$.validator.addMethod("nls", function (value, element) {
return this.optional(element) || /^[a-zA-Z0-9\s.\-_']+$/i.test(value);
}, "Please Only Enter Alpha Numeric Characters");
$.validator.addMethod("phone", function (value, element) {
return this.optional(element) || /(\s*\(?0\d{4}\)?\s*\d{6}\s*)|(\s*\(?0\d{3}\)?\s*\d{3}\s*\d{4}\s*)/i.test(value);
}, "Please Only Enter UK Telephone Numbers");
});
</script>
</head>
<body>
<div id="Site_Holder">
<div id="Header_Holder">
<?php include_once "PHP/Inserts/Header_Content.php";?>
</div><!-- Header Holder End -->
<div id="Navigation_Holder">
<?php include_once "PHP/Inserts/Navigation_Content.php";?>
</div><!-- Navigation Holder End -->
<div id="Content_Holder">
<div id="Register_Form_Holder" class="General_text">
<div class="Blank_Divider">Register a Climbing Centre<br/>
<br/></div>
<div class="Blank_Divider"></div>
<form id="SignUp">
<div class="Name_Form_Field">E-mail Address:</div>
<div class="Input_Form_Field"><input id="email" name="email"/></div>
<div class="Blank_Divider"></div>
<div class="Name_Form_Field">Password:</div>
<div class="Input_Form_Field"><input id="password" name="password" type="password" /></div>
<div class="Blank_Divider"></div>
<div class="Name_Form_Field">Confirm Password:</div>
<div class="Input_Form_Field"><input id="confirm_password" name="confirm_password" type="password" /></div>
<div class="Blank_Divider"></div>
<div class="Blank_Divider">Header
<br/>
<br/></div>
<div class="Name_Form_Field"> Name:</div>
<div class="Input_Form_Field"><input id="company" name="company" type="text" /></div>
<div class="Blank_Divider"></div>
<div class="Name_Form_Field">Contact Telephone Number:</div>
<div class="Input_Form_Field"><input id="telephone" name="telephone" type="text" /></div>
</form>
</div>
</div><!-- Content Holder End -->
<div id="Footer_Holder">
<?php include_once "PHP/Inserts/Footer_Content.php";?>
</div><!-- Footer Holder End -->
</div><!-- Site Holder End -->
</body>
</html>
你問該插件的默認行爲替換您的驗證碼。顯示你的代碼,以便我們可以看到你的錯在哪裏。 – Sparky
您忘記在代碼中包含表單的HTML標記。 – Sparky