Jim*_*med 5 php regex email validation ios
我正在开发一个最终允许用户相互联系的应用程序,但首先用户将能够发布一些公共信息,我想阻止他们发布联系信息(主要是电子邮件和电话号码)。
是否有适用于 iOS 或 PHP 的算法或方法可以检测此类信息?(注意 - 这不是一个简单的正则表达式。我想防止用户向公众显示他们的联系信息的常见“棘手”方式)。
我想阻止的例子:
显然,上面的例子和其他例子有无限的推导,所以我不能只为它们创建一个“快速”的表达式匹配算法。
我知道可能没有 100% 完美的方法,但是很好奇是否有比从头开始制作更好的东西。
对于电子邮件我总是使用这个正则表达式
("([a-zA-Z0-9._%+-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)")
Run Code Online (Sandbox Code Playgroud)
对于其他电子邮件,不使用正则表达式,而是使用字符串搜索
if line.tolower.contains("dot") and line.tolower.contains("com")
or if line.tolower.contains("@") and "com"
or if line.tolower.contains("@") and "net"
or if line.tolower.contains("mail") and "com"
or if line.tolower.contains("gmail") or "Yahoo" or "hotmail" or "bing"
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,您将必须制定很多规则
对于电话号码
("(?:\b\d{10,11}\b)")
("[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]")
Run Code Online (Sandbox Code Playgroud)
然后就像电子邮件一样,您将必须使用 .Contains
确保覆盖所有号码的唯一方法 - 您需要以字母形式添加一系列区域代码,例如:
"twosixfive"
"fourninesix"
Run Code Online (Sandbox Code Playgroud)
也:
"two six five"
"four nine six"
Run Code Online (Sandbox Code Playgroud)
也:
"two-six-five"
"four-nine-six"
Run Code Online (Sandbox Code Playgroud)
以下是所有区号的列表:http ://en.wikipedia.org/wiki/List_of_NANP_area_codes
数量并不多,你只需要愿意花时间去做就可以了。
| 归档时间: |
|
| 查看次数: |
1044 次 |
| 最近记录: |