我通常不会在这样的地方提问,因为它充满了我可能会发现可以解决我的问题的信息。然而,我是PHP,Javascript等新手。我似乎无法理解我遇到的这个问题,所以我转向你们,非常感谢你们的帮助。Javascript电子邮件验证
所以,我正在玩一个评论系统,一个创建者,但想作为一个Javascript函数来检查电子邮件的验证。这是因为遵循了代码...
$(function() {
//alert(event.timeStamp);
$('.new-com-bt').click(function (event) {
$(this).hide();
$('.new-com-cnt').show();
$('#name-com').focus();
});
/* when start writing the comment activate the "add" button */
$('.the-new-com').bind('input propertychange', function() {
$(".bt-add-com").css({
opacity: 0.6
});
var checklength = $(this).val().length;
if (checklength) {
$(".bt-add-com").css({
opacity: 1
});
}
});
/* on clic on the cancel button */
$('.bt-cancel-com').click(function() {
$('.the-new-com').val('');
$('.new-com-cnt').fadeOut('fast', function() {
$('.new-com-bt').fadeIn('fast');
});
});
// on post comment click
$('.bt-add-com').click(function() {
var theCom = $('.the-new-com');
var theName = $('#name-com');
var theMail = $('#mail-com');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9] {2,4})+$/;
if (!theCom.val()) {
alert('oh! Don`t forget your message!');
}
if (!filter.test(theMail.value)) {
alert('Please provide a vaild email address');
theMail.focus;
return false;
} else {
$.ajax({
type: "POST",
url: "ajax/add-comment.php",
data: 'act=add-com&id_post=' + <? php echo $id_post; ? > +'&name=' + theName.val() + '&email=' + theMail.val() + '&comment=' + theCom.val(),
success : function (html) {
theCom.val('');
theMail.val('');
theName.val('');
$('.new-com-cnt').hide('fast', function() {
$('.new-com-bt').show('fast');
$('.new-com-bt').before(html);
})
}
});
}
});
});
正如你可以看到我提供了一个变种过滤器等等...但简单的语言解释,最终的结果是它会提醒说电子邮件是无效的,但是当输入一个有效的电子邮件并尝试提交,无论它刚刚提出了警报和最终结果,这意味着发生的事情根本不会。
对不起,如果我对此有所了解或对此没有任何了解,但我愿意协助。
再次,任何帮助将不胜感激。
谢谢