0

On one of my sites, I have a problem with too many NEW users not reading the rules and posting their phone numbers in public, which is against the rules.

So to put an end to this, I want to check whether a phone number has been submitted before making the post live. What is the best and most efficient way to determine whether a phone number appears in a string?

Here's my thought process on this:

1) Phone numbers are at least 10 digits.

2) Sometimes users use (, ), -, and spaces within their phone numbers.

So, to check whether a phone number has been posted, it seems like I would have to get the string of the post, remove all of the characters from 2) above, and then search for any occurrence of 10 consecutive digits or more.

Of course, this could be circumvented, but the vast majority of new users aren't trying to circumvent the rules, they are just posting their phone numbers completely oblivious to the rules and I don't know how else to stop them so that I don't have to waste so much time moderating the site.

How would I do the above in PHP? Or is there a better way?

Edit: To clarify, my site already has a "report post" button for users to report offending posts, which is how I moderate the site, but 90% of my of my moderation time is spent having to edit out phone numbers and warn those users not to do it. I want to "preempt" the problem so to speak by catching it before it happens, and warning the user about the rules. Sure, users can circumvent it, but then I'll just ban them since they were specifically warned not to do it, and I can't fathom many users knowingly ignoring the rules just to get banned. So my solution would save me A LOT of time, with minimal drawbacks. I just can't fathom many cases on my site where 10 or more consecutive digits are entered that aren't phone numbers, so I'm not worried about false positives.

ProgrammerGirl
  • 3,157
  • 7
  • 45
  • 82
  • From experience, the problem is *never* with new users not reading the rules - it's with your interface not anticipating this from the start. – Adam Hopkinson Aug 19 '12 at 11:37
  • A major part of designing a website (or any other tool) is anticipating various use cases and either mitigating or managing them. You can't blame your users for missing your rules or posting phone numbers, this could have easily been predicted from the start. – Adam Hopkinson Aug 19 '12 at 19:09

3 Answers3

2

What is the best

Checking the posts manually (I guess not a valid option, but it is the best).

most efficient way

Don't do it.

Of course, this could be circumvented,

Wrong. It will be circumvented, both by new and current users.

Sorry that this isn't really an answer to your question, but it is the only correct answer imho.


You could however run some regex pattern over the posts to check whether there might be phonenumbers in it, but there are two drawbacks of doing this:

  1. Users will circumvent this and you will not be able to trap them all
  2. You might get false positives which is very very annoying for users.

If you really want to go this route the best course of action imo is to get a big set of posts with phonenumbers in it and make a list of all the possible formats of phonenumbers you find in it. Once you have that list you can write a regex pattern based on this list.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
  • I have to disagree. If it's circumvented, I'll still catch it like I've already been doing, so that's not a problem. The purpose of this is to reduce my workload moderating the site. And as for false positives, I can't fathom many cases on my site where 10 or more consecutive digits are entered that aren't numbers. I'm afraid I can't accept your answer as it is, but I would be more than happy to accept it if you could at least provide the answer to the solution I proposed. Thanks. – ProgrammerGirl Aug 19 '12 at 11:50
  • Have you read my entire answer? I already have provided a possible solution. – PeeHaa Aug 19 '12 at 11:51
  • Yes, I read it, but I don't know how to program what either you or I suggested as possible solutions. Thanks. – ProgrammerGirl Aug 19 '12 at 11:53
1

You could remove all the characters you've mentioned in 2) then use a regex like the one here: https://stackoverflow.com/a/3764902/1130734 to find the numbers like this

$string = preg_replace('/[() -]+/','',$string);
$found = preg_match("/\+?[0-9][0-9()-\s+]{4,20}[0-9]/",$string);
if ($found==1){
    //tell user they may be breaking the rules and face a ban
}

You may want to change the regex so it only matches numbers that start with a zero or a plus symbol (not sure if this is right though...) /[0\+][0-9()-\s+]{4,20}[0-9]/

Community
  • 1
  • 1
Timm
  • 12,553
  • 4
  • 31
  • 43
  • I already have a "Report this post" button, but even then, 90% of my moderation time is spent having to edit out phone numbers and warn those users not to do it. I want to "pre-empt" the problem so to speak. Sure, users can circumvent it, but then I'll just ban them since they were warned not to do it, and I can't fathom many users knowingly ignoring the rules just to get banned. So my solution would save me A LOT of time, with minimal drawbacks. How could I implement the solution I proposed in PHP? Thanks. – ProgrammerGirl Aug 19 '12 at 11:52
0

You best bet is to use a regular expression to search to common formats of phone numbers. This can be constantly reviewed and improved through experience

However, humans a cunning creatures so you will never eliminate it.

EDIT

Of course you can use PHP.

Just add into the code the does the posting on your site some validation - i.e. perform checks to ensure that the post obeys the rules.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127