我已经在这个工作了几个小时了,似乎无法使它工作.
我在客户端部分需要多个电子邮件,位于相同的输入字段中.
我在客户端部分需要多个电子邮件,位于相同的输入字段中.
现在我有(适用于一封电子邮件):
<script language="JavaScript"> $(document).ready(function(){ $("form#editclient").validate({ rules: { Contact: { required: true },Clientname: { required: true },ClientLogin: { required: true },ClientPassword: { required: true },email: { required: true,multiemail: true } },messages: { Contact: { required: "Please enter your Contact Nmae." },Clientname: { required: "Please enter your Client Name" },ClientLogin: { required: "Please enter a login." },ClientPassword: { required: "Please enter a password" },email: { required: "Please enter an Email Address",multiemail: "You must enter a valid email,or comma separate multiple" } } }); }); </script> <input type="Text" id="email" name="Email" value="#Trim(Email)#" maxlength="60" class="inputText430 email required">
我发现这应该让多个验证器工作:
jQuery.validator.addMethod( "multiemails",function (value,element) { if (this.optional(element)) // return true on optional element return true; var email = value.split(/[;,]+/); // split element by,and ; valid = true; for (var i in email) { value = email[i]; valid = valid && jQuery.validator.methods.email.call(this,$.trim(value),element); } return valid; },jQuery.validator.messages.multiemail);
但我不能让它正常工作.有人可以帮助我在一个文本字段中验证2个或更多电子邮件吗?
提前致谢.
(已编辑以在规则和消息中添加多重邮件)
(用下面的解决方案编辑)
解
<form> <input id='emailTest' name='emailTest' /> <input type='submit' /> </form> <script type="text/javascript"> jQuery.validator.addMethod( "multiemail",element) { var email = value.split(/[;,and ; valid = true; for (var i in email) { value = email[i]; valid = valid && jQuery.validator.methods.email.call(this,element); } return valid; },jQuery.validator.messages.multiemail ); $("form").validate({ debug: true,rules: { emailTest: { multiemail: true } },messages: { emailTest: { multiemail: "You must enter a valid email,or comma separate multiple" } },submitHandler: function(form) { return false; } });