2013-03-01 92 views
0

我正在尋找添加確認電子郵件字段到我的聯繫表格..我知道如何添加確認電子郵件字段,但我不知道如何添加JavaScript以匹配確認電子郵件到原件電子郵件。任何人都可以幫助我,或有一個我可以學習的教程?由於如何添加確認電子郵件驗證

接觸HTML表單:

<div id="contactcontainer"> 
<div id="form"> 
<h3>Contact Us</h3> 
<form action="contact.php" method="post"> 
<p> 
<label for="name">Name:</label> 
<input name="name" id="name" type="text" class="required"> 
<span>Please enter your name</span> 
</p> 
<p> 
<label for="email">Email:</label> 
<input name="email" id="email" type="text" class="required"> 
<span>Please enter a valid email address</span> 
</p> 
<p> 
<label for="number">Phone Number:</label> 
<input name="number" id="number" type="text" class="required"> 
<span>Please enter your phone number</span> 
</p>   
<p> 
<label for="date">Trip Date:</label> 
<input name="date" type="text" id="datepicker" class="required"/> 
<span>Please select a date</span> 
</p>  
<p> 
<label for="subject">Subject:</label> 
<input name="subject" id="subject" type="text"> 
<span>Please enter your subject</span> 
</p> 
<p> 
<label for="message">Message</label> 
<textarea name="message" id="message" class="required"></textarea> 
<span>Please enter your message</span> 
</p>   
<p> 
<input type="submit" value="Submit" class="btn-submit"> 
</p> 
</form> 
</div> 
</div> 

的Javascript:

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript"> 
var $submit = $(".submit input"); 
var $required = $(".required"); 
function containsBlanks(){ 
var blanks = $required.map(function(){ return $(this).val() == "";}); 
return $.inArray(true, blanks) != -1; 
} 
function isValidEmail(email){ 
return email.indexOf("@") != -1; 
} 
function requiredFilledIn(){ 
if(containsBlanks() || !isValidEmail($("#email").val())) 
$submit.attr("disabled","disabled"); 
else 
$submit.removeAttr("disabled"); 
} 
$("#form span").hide(); 
$("input,textarea").focus(function(){ 
    $(this).next().fadeIn("slow"); 
    }).blur(function(){ 
    $(this).next().fadeOut("slow"); 
    }).keyup(function(){ 
//Check all required fields. 
requiredFilledIn(); 
}); 
$("#email").keyup(function(){ 
//Check for a valid email. 
if(isValidEmail($(this).val())) 
$(this).next().removeClass("error").addClass("valid"); 
else 
$(this).next().removeClass("valid").addClass("error"); 
    }); 

requiredFilledIn(); 
</script> 

回答

0

只是透過這兩個字段的值,並確保然後是==來驗證它。對於不區分大小寫,您應該將其轉換爲全部上限或下限。