gpt4 book ai didi

jquery - 无法在 Jquery 中进行电子邮件验证

转载 作者:行者123 更新时间:2023-11-28 04:13:42 25 4
gpt4 key购买 nike

大家好,我的 jQuery 有点问题,我的所有输入验证都在工作,但我无法让我的 REGEX 代码工作来验证我的电子邮件。尝试输入“hello@mywebsite.co.uk”我的个人电子邮件和我的工作电子邮件,但它们都不起作用。

非常感谢任何帮助。

var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
$('.submitbutton').click(function () {
if ($("input.name").val() == '') {
alert("Name is a required field");
return false;
}
else if ($("input.email").val() == '') {
alert("Email is a required field");
return false;
}
else if (!regex.test("input.email")) {
alert("This is not a valid email address");
return false;
}
else if ($("textarea.message").val() == '') {
alert("Message is a required field");
return false;
}
else {
return true;
}
});

干杯

最佳答案

regex.test("input.email") 中,您正在测试实际字符串 "input.email" 是否与正则表达式匹配。相反,您应该测试 input.email 元素的

所以使用:

regex.test($("input.email").val())

关于jquery - 无法在 Jquery 中进行电子邮件验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11017612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com