使用jQuery和regex验证电子邮件地址我不太确定该怎么做。我需要使用regex验证电子邮件地址,如下所示:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mi
l|biz|info|mobi|name|aero|asia|jobs|museum)然后,我需要在这样的jQuery函数中运行这个函数:$j("#fld_emailaddress").live('change',function() { var emailaddress = $j("#fld_emailaddress").val();// validation here? if(emailaddress){}
// end validation$j.ajax({
type: "POST",
url: "../ff-admin/ff-register/ff-user-check.php",
data: "fld_emailaddress="+ emailaddress,
success: function(msg)
{
if(msg == 'OK') {
$j("#fld_username").attr('disabled',false);
$j("#fld_password").attr('disabled',false);
$j("#cmd_register_submit").attr('disabled',false);
$j("#fld_emailaddress").removeClass('object_error'); // if necessary
$j("#fld_emailaddress").addClass("object_ok");
$j('#email_ac').html(' <img src="img/cool.png" align="absmiddle">
<font color="Green"> Your email <strong>'+ emailaddress+'</strong> is OK.</font> ');
} else {
$j("#fld_username").attr('disabled',true);
$j("#fld_password").attr('disabled',true);
$j("#cmd_register_submit").attr('disabled',true);
$j("#fld_emailaddress").removeClass('object_ok'); // if necessary
$j("#fld_emailaddress").addClass("object_error");
$j('#email_ac').html(msg);
}
}
});});验证到哪里去了,表达式是什么?
3 回答
回首忆惘然
TA贡献1847条经验 获得超11个赞
function isValidEmailAddress(emailAddress) { var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i); // alert( pattern.test(emailAddress) ); return pattern.test(emailAddress);};
哈士奇WWW
TA贡献1799条经验 获得超6个赞
$(document).ready(function() {$('#emailid').focusout(function(){ $('#emailid').filter(function(){ var emil=$('#emailid').val(); var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; if( !emailReg.test( emil ) ) { alert('Please enter valid email'); } else { alert('Thank you for your valid email'); } }) });});
- 3 回答
- 0 关注
- 633 浏览
添加回答
举报
0/150
提交
取消