我需要为联系表验证我的电子邮件和电话。那里有用于电子邮件的代码,但它不正确,而且不是正确的方法,没有任何帮助!我知道它需要它说:
if(email.length == 0 || email.indexOf('@') == '-1')
但我现在确定如何做到这一点,我对 php 很陌生,所以对我来说放轻松:)
var error = false;
var name = $('#name').val();
var email = $('#email').val();
var subject = $('#subject').val();
var message = $('#message').val();
var tel = $('#tel').val();
// Form field validation
if(name.length == 0){
var error = true;
$('#name_error').fadeIn(500);
}else{
$('#name_error').fadeOut(500);
}
if(tel.length == 0){
var error = true;
$('#tel_error').fadeIn(500);
}else{
$('#tel_error').fadeOut(500);
}
if(email.length == 0 || email.indexOf('@') == '-1'){ **this is not the right way! help**
var error = true;
$('#email_error').fadeIn(500);
}else{
$('#email_error').fadeOut(500);
}
if(subject.length == 0){
var error = true;
$('#subject_error').fadeIn(500);
}else{
$('#subject_error').fadeOut(500);
}
if(message.length == 0){
var error = true;
$('#message_error').fadeIn(500);
}else{
$('#message_error').fadeOut(500);
}
if(tel.length == 0){
var error = true;
$('#tel_error').fadeIn(500);
}else{
$('#tel_error').fadeOut(500);
}