如何在每个逗号分隔的情况下仅允许和验证10封电子邮件或最少。它应该只允许10封电子邮件或最少,每封电子邮件都以逗号分隔。现在我只能验证用逗号分隔的每封电子邮件
<form method="post" action="" id="add_engagement" name="add_engagement" class="form-horizontal">
<tr><td>Email Recipients</td>
<td><textarea name="email_recipients" id="email_recipients" >{$Notification.email_recipients}</textarea><br/><span style="color:red">*</span>Note: Separated by commas(,)</td>
</tr>
<input type="submit" class="post_button" id="edit_notification" value="Update" name="edit_notification" /></td></tr>
</form>
<script>
$(function(){
$('#edit_notification').one('click', function () {
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$.validator.addMethod('multiEmails', function(value, element) {
if (this.optional(element)) {
return true;
} else {
var valid = true;
$.each($.trim(value).replace(/,$/, '').split(','), $.proxy(function (index, email) {
if (!$.validator.methods.email.call(this, $.trim(email), element)) {
valid = false;
}
}, this));
return valid;
}
}, 'One or more email addresses are invalid');
$("#add_engagement").validate({
rules: {
email_recipients: {
required: true,
multiEmails:true,
},
},
messages: {
email_recipients: {
required: "Please enter email",
},
},
submitHandler: function(form) {
form.submit();
},
});<script>
答案 0 :(得分:1)
您可以添加计数器:
SELECT LicensePlateNo FROM car
LEFT JOIN CarTransaction ON car.ChassisNo = CarTransaction.ChassisNo
LEFT JOIN Sell ON CarTransaction.TransactionID = Sell.TransactionID
LEFT JOIN Rent ON CarTransaction.TransactionID = Rent.TransactionID
WHERE Car.Make = 'Toyota'
AND Sell.TransactionID IS NULL
AND Rent.TransactionID IS NULL
或者您可以在电子邮件地址数量上添加另一个验证规则,并附带单独的错误消息。