[英]Jquery validate multiple inputs with email
I have a form where i ask the user to input email addresses for an automated email to be sent. 我有一个表格,要求用户输入电子邮件地址以发送自动电子邮件。 I have set both the email inputs to be required and to check for valid email, but it seems to work only for the first one. 我设置了电子邮件输入为必填项,并检查了有效的电子邮件,但它似乎仅对第一个有效。 What am I doing wrong here? 我在这里做错了什么?
<form class="validate" method="post" id="formLoc">
<div data-role="fieldcontain">
<label for="email-from">from</label>
<input type="text" class="required email" id="email-from" placeholder="from" />
</div>
<div data-role="fieldcontain">
<label for="email-to">to</label>
<input type="text" id="email-to" class="required email" placeholder="to" />
</div>
<div data-role="fieldcontain">
<label for="email-message">message</label>
<textarea id="email-message" cols="100" rows="40"></textarea>
</div>
<div class="email-sent">
<h4></h4>
</div>
<div class="SendEmailButton">
<button type="submit" data-role="button" data-icon="forward" data-inline="true"
data-mini="true" data-theme="c">send</button>
</div>
</form>
Here's a fiddle with the problem : http://jsfiddle.net/bobby5193/8dHg9/544/ 这是一个摆弄这个问题的小提琴: http : //jsfiddle.net/bobby5193/8dHg9/544/
Add the name
attribute to both input fields. 将name
属性添加到两个输入字段。
<input type="text" name="email-from" class="required email" id="email-from" placeholder="from" />
<input type="text" name="email-to" id="email-to" class="required email" placeholder="to" />
<textarea name="email-message" id="email-message" cols="100" rows="40" class="required"></textarea>
Here is a jsFiddle 这是一个jsFiddle
Update 更新资料
Here is an updated jsFiddle which has validation on the textarea
. 这是一个更新的jsFiddle ,它对textarea
进行了验证。 I added the name
attribute and class="required"
to it. 我在其中添加了name
属性和class="required"
。
If you want get more than one text box to insert Email like 如果您想获得多个文本框来插入电子邮件,例如
<ul>
<li>
<input id="emailcheck" type="text" placeholder="Email" name="ToEmails[0]" required />
<input id="emailcheck" type="text" placeholder="Email" name="ToEmails[1]" required />
<input id="emailcheck" type="text" placeholder="Email" name="ToEmails[2]" required />
</li>
</ul>
Now we will get all email address from text box. 现在,我们将从文本框中获取所有电子邮件地址。
var email = $('input[name^=ToEmails]');
console.log(email);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.