beechy34 Posted March 26, 2009 Share Posted March 26, 2009 hi this is my code for phone number if (ereg("(^[0-9]{6,6})$", $phone)){echo "$phone";} what i would have to be done to allow whitespace in between the numbersthankyou Link to comment Share on other sites More sharing options...
jeffman Posted March 26, 2009 Share Posted March 26, 2009 Your best bet is not to allow anything non-numerical. Tell your users that, and then make them correct the entry if they add ANY characters that are not numbers. There are too many ways a phone number can be written, too many extra characters they can add, and too many mistakes they can make, to try to allow them all.For the last 8-10 years, whenever I have registered with a serious corporation, the site only allows digits for phone numbers and credit card numbers. People are used to that. They won't complain, as long as you instruct them what to do. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 26, 2009 Share Posted March 26, 2009 It's also easy enough to just remove all non-number characters. I think that's probably a little more user-friendly than requiring a specific format, when the computer can just reformat it for you. Link to comment Share on other sites More sharing options...
jeffman Posted March 26, 2009 Share Posted March 26, 2009 Easy, and in this case harmless enough, since you know the user's intent. I just have this security mindset that you should generally reject questionable data instead of altering it. This is probably a useful exception. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 26, 2009 Share Posted March 26, 2009 I normally just give it one of these:$phone = str_replace(array('-', '.', '(', ')', ' '), '', $phone); Link to comment Share on other sites More sharing options...
boen_robot Posted March 27, 2009 Share Posted March 27, 2009 It's also easy enough to just remove all non-number characters. I think that's probably a little more user-friendly than requiring a specific format, when the computer can just reformat it for you.I was just suggesting that in another topic. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.