How to prevent users from entering contact details (emails / phone numbers) in text inputs?

I am working on an application that will ultimately allow users to connect to each other, but first the user will be able to publish some publicly available information, and I want to block them from publishing contact information (mainly by email and phone numbers).

Is there an algorithm or approach for iOS or PHP that can detect such information? (Note: This is not a simple regular expression. I want the usual "tricky" ways for users to display their contact details to the public).

Examples of what I want to block:

  • Call me on 123-123-1234
  • Call me one-two-three times three-three-four.
  • Email me johnsmith@gmail.com
  • Let me know that John Smith at g mail dot com

Obviously, there are unlimited conclusions from the above examples and others, so I can’t just create a “fast” matching algorithm for them.

I know there is probably not a 100% perfect approach for this, but it was curious if there was anything there that would be better than making my own from scratch.

+3
source share
1 answer

For email, I always use this regex

 ("([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})(\]?)")

for other letters, instead of using regular expressions, use string search

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"

As you can see, you will need to make a few rules

For telephone numbers

("(?:\b\d{10,11}\b)")
("[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]")

Then, like letters, you will need to use .Contains

, - :

"twosixfive"
"fourninesix"

:

"two six five"
"four nine six"

:

"two-six-five"
"four-nine-six"

: http://en.wikipedia.org/wiki/List_of_NANP_area_codes

, , .

+2

All Articles