[英]Detect any attempt to insert an email address or phone number
How can I detect from input boxes any attempt to insert an email address or phone number. 我如何从输入框中检测到任何尝试插入电子邮件地址或电话号码的尝试。 This is the main scenario: we have some inputs where user should only write what they are for, like name or street or features.
这是主要场景:我们有一些输入,用户仅应输入其用途,例如名称或街道或要素。
How can I detect/verify after the user submits that in all that data he sends there are no: emails/phone numbers. 如何在用户提交之后检测/验证在他发送的所有数据中没有:电子邮件/电话号码。 Take in consideration that I also have to eliminate this kind of tries: email at domain dot com, emails @ [spaces] dot [spaces] com and so on.
考虑到我还必须消除这种尝试:域dot com上的电子邮件,@ [spaces]点[spaces] com上的电子邮件等等。
Are there any plugins, tools out there we can use? 我们可以使用哪些插件,工具? Do you have an idea about this?
您对此有想法吗? Let's put it to the test.
让我们对其进行测试。
We are building a web application. 我们正在构建一个Web应用程序。 (php/javascript mainly)
(主要是php / javascript)
Use a jQuery plugin for validation - then use regex (or some of the already built in functions) to validate the input ... 使用jQuery插件进行验证-然后使用正则表达式(或某些已经内置的函数)来验证输入...
I use the Position Absolute validator for jQuery 我为jQuery使用Position Absolute验证器
If you are searching for jQuery validation plugins there are tons of them. 如果您正在搜索jQuery验证插件,那么它们就有很多。
Eg http://bassistance.de/jquery-plugins/jquery-plugin-validation/ or search Google for "jquery validation plugin" 例如http://bassistance.de/jquery-plugins/jquery-plugin-validation/或在Google上搜索“ jquery验证插件”
Also validate your input server-side with php after submit, because Javascript can be disabled in the browser. 也可以在提交后使用php验证您的输入服务器端,因为可以在浏览器中禁用Javascript。
There are also many tutorials out there (eg http://myphpform.com ), or search SO. 还有很多教程(例如http://myphpform.com )或搜索SO。
HTML HTML
<input type="text" id="lname" name="lname" />
<input type="submit" value="Submit" name="submit" onclick="return validate();"/>
in Javascript 用Java语言编写
function validate()
{
var regex = /^[a-zA-Z_]+$/;
var lname = document.getElementById('lname').value;
if (regex.test(lname)) {
return true;
} else {
return false;
}
}
you can edit regex to suit your criteria 您可以编辑正则表达式以符合您的标准
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.