简体   繁体   English

输入字段必须包含允许表单提交的特定字符

[英]Input fields must include specific character to be allowed for the form to submit

I am trying to prevent as much spam form submissions on a lead generation form from happening.我试图防止在潜在客户生成表单上提交尽可能多的垃圾邮件表单。 The idea is to ensure the email field must include an @ symbol and the website field must include a '.'.这个想法是确保 email 字段必须包含 @ 符号,并且网站字段必须包含“。”。 How would I go about achieving this with JS.我将如何使用 JS 实现这一目标。

Just a heads up, I am using contact form 7 on Wordpress so any solutions for that would be amazing.请注意,我在 Wordpress 上使用联系表 7,因此任何解决方案都会令人惊叹。

If you have any questions please ask:)如果您有任何问题,请询问:)

you can use regex to evaluate your email您可以使用正则表达式来评估您的 email

function validateEmail(email) {
    const reg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return reg.test(String(email).toLowerCase());
}

All you need to do is just pass the entered email to this function and it will help you determine whether its a valid or invalid one您只需将输入的 email 传递给此 function,它将帮助您确定它是有效的还是无效的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM