答案 0 :(得分:3)
检查有效的正则表达式和长度。你的正则表达式是一个空场的成功。
你在这里检查jQuery元素集合的长度
if(!$("#sForm input#write").length > 0) $("input#sub").hide();
但你必须检查值的长度
detectEmail.length == 0
$('input#sub').hide();
$('input').keyup(function() {
$('span.attention').hide();
var detectEmail = $(this).val();
var emailRegex = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(detectEmail.length == 0 || !emailRegex.test(detectEmail))
{
$('#sub').hide();
$(this).after('<span class="attention">Writing valid e-mail...</span>');
}
else
{
$('#sub').show();
}
});
答案 1 :(得分:0)
检查空字符串实际上是错误的。
这个返回元素的数量(总是1):
$("#sForm input#write").length
改为这样的
$("#sForm input#write").val().length