我有一个jquery语法如下
Email: {
required: true,
email: true,
remote: {
url: "emails.php",
type: "post",
},
验证字段如下;
<td class="field" style="width: 246px">
<input id="Email" name="Email" type="text" value="<?php echo $email; ?>" style="width: 246px">
</td>
<td class="status"></td>
在<td class="status">
在输入有效的电子邮件ID时验证数据。
ajax回调是一个简单的真/假数据。
我想要的是,它还应验证在字段中输入特定消息“NA”的时间。这可能吗?
这是完整的javascript;
<script id="demo" type="text/javascript">
$.noConflict();
jQuery(document).ready(function($) {
var validator = $("#signupform").validate({
rules: {
ID: "required",
Name: {
required: true,
minlength: 5,
},
Address: "required",
Dept: "required",
Phone: "required",
College: "required",
LDate: "required",
EDate: "required",
Year: "required",
Privilage: "required",
username: {
required: true,
minlength: 5,
},
Email: {
required: true,
email: true,
remote: {
url: "emails.php",
type: "post",
},
},
LibID: {
required: true,
},
},
messages: {
ID: "Enter ID",
Name: "Enter Name",
Address: "Enter Address",
Phone: "Enter Phone Number",
College: "Specify College",
LDate: "Enter Licenseing Date",
EDate: "Specify License Expiry Date",
Year: "Specify Year",
Dept: "Specify Department",
Privilage: "Specify Privilage",
username: {
required: "Enter a username",
minlength: jQuery.format("Enter at least {0} characters"),
remote: jQuery.format("username not available")
},
Email: {
required: "Enter a valid email address",
minlength: "Enter a valid email address",
remote: jQuery.format("already registered"),
},
LibID: {
required: "Enter a Library ID",
minlength: "Enter a Library ID",
remote: jQuery.format("ID is already in use"),
},
},
errorPlacement: function(error, element) {
error.appendTo( element.parent().next() );
},
success: function(label) {
label.html("OK").addClass("checked");
}
});
$('.username').alphanumeric({nocaps:true}).alphanumeric({ichars:'._'});
});
</script>
提前致谢:)
blasteralfred。
答案 0 :(得分:0)
我假设您正在使用jquery.validation插件。 如果是这种情况,您可以使用取决于电子邮件规则:
Email: {
required: true,
email: {
depends: function(element){
return element.value != "NA";
}
},
remote: {
url: "emails.php",
type: "post",
},
}