关于 jquery:检查有效的电子邮件地址 | 珊瑚贝

Checking for a valid email address

本问题已经有最佳答案,请猛点这里访问。


Possible Duplicate:
Validate email address in Javascript?
Validate email with jQuery

目前我在我建立的联系表格中使用它来检查电子邮件字段是否留空

1
2
3
4
5
6
    var email = $(“input#email”).val();  
            if (email ==””) {  
            $(“label#email_error”).show();  
            $(“input#email”).focus();  
        return false;  
        }

如何检查电子邮件输入字段是否包含 @ 字符?

  • 可能重复 Validate email with jQuery 和 How to validate textbox for emailid using JQuery?。


将 if (email ==””) { 更改为 if (!(email.indexOf(‘@’) > 0)) {。这将确保:

  • 该字符串包含 @。
  • @ 不是第一个字符。
  • 字符串不为空。

示例:

1
2
3
4
5
6
var email = $(“input#email”).val();
if (!(email.indexOf(‘@’) > 0)) {
    $(“label#email_error”).show();
    $(“input#email”).focus();
    return false;
}
  • 我试过了,但没有用。实际上,该字段是空白时提交的表单。
  • 我现在意识到逻辑错误。它必须是 NOT\\’d。修改后的答案,请再试一次,让我们知道。


How can I run a check that the email input field contains an @ character?

足够简单:

1
2
3
4
if(email.indexOf(‘@’) == -1)
{
    /* no @ in the string */
}

但是,这不足以验证电子邮件地址。请参阅上一个问题:在 JavaScript 中验证电子邮件地址?

  • 这行得通,但你是对的,更健壮的东西更好。


来源:https://www.codenong.com/9349787/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_10138.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?