nevynev Posted August 31, 2007 Share Posted August 31, 2007 Hi, Im making a profanity, email and phone number filter script. So far I've tackled swearing and emails but phone numbers is a little more tricky. How would I scan for a group of numbers more than 6 characters long in any format e.g. 012345678 01234 567 891 0 1 2 3 4 5 6 7 8 9 1 0-1-2-34-5-6789 0*1#2+3456]4 And so on... I know its regular expressions but I want to have it so it picks up all kinds of combos but doesnt mess up e.g. someone typing in e.g. £100.00 (less than 6 consecutive characters). Of course if someone really wanted to work around it they could but I want to put people off trying. Thanks for any help! NevyNev Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/ Share on other sites More sharing options...
soycharliente Posted August 31, 2007 Share Posted August 31, 2007 I'm not up on the regex terminology or syntax, but I think it sounds like you want something like ... (and I don't know how many characters you want them to be able to check for in between the numbers) Any number, 0-2 other characters, Any number, 0-2 other characters, etc.. until you get to however long the phone number is. "^([0-9](.{0-2}){10}$" I have no idea if that will work. But that wouldn't like people type in something like... $10,000,000.00 because it satisfies that condition it seems, though I haven't tested it. Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338583 Share on other sites More sharing options...
gerkintrigg Posted August 31, 2007 Share Posted August 31, 2007 Hmm that's a tricky one... how about starting simply: $string ='My telephone number is: 01111 111 111'; Then cut out all the spaces: $check=explode(' ', $string); $new_string=implode($check); You can then do the same with all the other characters. Once you have done that you either do a counter script for each time you come across a number or cut all of them out: $num=array('0','1','2','3','4','5','6','7','8','9'); $no_of_numbers=explode($num, $new_string); To do a count script use a for_each loop with a ++ incrementing variable. Hope this helps, but doubt it does because I seem to have confused myself. Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338597 Share on other sites More sharing options...
Daniel0 Posted August 31, 2007 Share Posted August 31, 2007 Perhaps you can use this? http://diveintopython.org/regular_expressions/phone_numbers.html Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338605 Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 Please do not double post. If you want your topic in the Regex forum I'll move it there. Pick one. This is a dangerous task since you're allowing any format. Can you narrow it down a bit? <pre> <?php $data = <<<DATA 012345678 01234 567 891 0 1 2 3 4 5 6 7 8 9 1 0-1-2-34-5-6789 0*1#2+3456]4 $10,000,000.00 The answer is 6.0221415 E+23. Meet me @ 5pm at Apartment 1 on 1500 Elm Street. DATA; echo preg_replace('# (?!\$) (?:\d[^\d,.\r\n]*){6,} #x', '', $data); ?> </pre> Yields: $10,000,000.00 The answer is 6.. Meet me @ . Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338608 Share on other sites More sharing options...
xyn Posted August 31, 2007 Share Posted August 31, 2007 or use eregi_match() and make a function to do all the formats? singly Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338616 Share on other sites More sharing options...
nevynev Posted August 31, 2007 Author Share Posted August 31, 2007 Well my main aim is to deter people from entering their phone numbers within any text field on the site, but it doesn't have to completely block all just most normaly attempts I suppose.Hope that narrows it down a bit. How about a search from when it finds a character which is a number and then checks the next e.g. 16 characters and if say 8 out of those 16 characters are numbers then it returns an error, assuming the numbers make up a phone number or someone trying to work around it.... Make sense? Thanks nevyNev Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338667 Share on other sites More sharing options...
effigy Posted August 31, 2007 Share Posted August 31, 2007 Is there a certain context to this site, e.g., would users be entering scientific notation for any reason? Have a look at this topic, and especially at the note about users spelling out numbers: "one", "two", etc. Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338674 Share on other sites More sharing options...
nevynev Posted August 31, 2007 Author Share Posted August 31, 2007 It is a form of social networking site so I guess people will be entering all kinds of things but not really anything scientific etc. From the other post - His solution: true must admit i didn't think of that (must be having an off day here) however i have now written the code to remove phone numbers but leave in in numbers such as 1000.00 or 1000. Im sure its not perfect but here it is "/([\(\+])?([0-9]{1,3}([\s])?)?([\+|\(|\-|\)|\s])?([0-9]{3,4})([\-|\)|\.|\s]([\s])?)?([0-9]{2,4})?([\.|\-|\s])?([0-9]{4,8})/","/\b()\b/i" Would like to know what you all think Is that too over the top? I.e. will I lose numbers like 100,000 or £1000000. I don't want to irritate my members. What do you think of his solution? Thanks NevyNev Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338695 Share on other sites More sharing options...
roopurt18 Posted August 31, 2007 Share Posted August 31, 2007 I have to wonder why you wouldn't want people to be able to post phone numbers or emails on a social networking site? Besides, once you get it down all I have to do is post with: I can be reached at $1,444,555,123.4 e123 Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338699 Share on other sites More sharing options...
nevynev Posted August 31, 2007 Author Share Posted August 31, 2007 I know its not for me, the person Im building it for wants it that way. Will test that post above. Thanks NevyNev Quote Link to comment https://forums.phpfreaks.com/topic/67444-filtering-out-phone-numbers-from-a-string/#findComment-338714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.