- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Besides either using IsDigit or a whitelist of chars, we allow anything in the text, simply because people can type
+44 (0)1234 56789
or
01234 56789 ext 3
etc.
Depends what you really need it for.
When I get asked for my phone number (usually for marketing spam) I put 0100 100000 which is good enough to defeat most form checks.
Admin
Then somebody comes along and adds the following for for a small software test
©®
Admin
No you don't do that. You put in a voip number that you get inbound calls deducted from your outbound call's :)
That way the marketing spam pays for your outbound calls :)
Admin
Did this programmer not go to school or something?
Admin
Ma Bell's Officially Recommended Exchange Names.
I use CApital 4-6195. Other than occasionally being asked how to make a capital 4, what's the problem?
http://ourwebhome.com/TENP/Recommended.html
Ma Bell's Officially Recommended Exchange Names
Admin
Of course the right way to validate the phone number is to hook a modem up to the server and dial it.
Admin
Simple. Put a Java class called VirtualPhone behind the page, with a typeKey(char keyValue, String contextBeanId) method which throws an exception if the key value is invalid, a simulateCall() method that throws if the number is invalid, and a getLastNumberDialled() method. Don't ask me about how exceptions are handled because I neither know nor care how the UI works.
Admin
IIRC A and C also cannot be 0.
Admin
Scala:
Admin
Unless the phone number starts with 110, 00 or +, in which case the next 1 - 4 numbers are a country code, and the rest is country dependant ^^
Admin
I think every CodeSOD should specify the language.
Admin
What, no backwards compatibility? "Pennsylvania Six Five Thousand!"
http://en.wikipedia.org/wiki/PEnnsylvania_6-5000
Admin
For extra lols when they specify the wrong one?
Admin
Except you'd get in trouble with p and w, as those characters actually have a meaning for dialers. I believe the functional set of characters is something along the lines of:
Though for readability the following set is added:
(I might have missed some, but those are the more common ones)
Admin
Erm, that last one should be [ -(),] of course ^^
Admin
Dude. Google "regular expressions". I swear it will blow your effing mind.
Admin
LOL! It should obviously have been
All those extra assignments are so unnecessary!
Admin
Or maybe:
employees.replace("programmer", "monkey");
Admin
He should have used functions for all of that redundant code:
Admin
So, say,
is a valid phone number?
Admin
Admin
Idea
number = number.replaceAll("\D",""); no to short and who knows \D anyway?
Idea number = number.replaceAll("[^\d"],""); yes but what if reader ist not that fluent in regexp, got to remove these predefined groups
Idea number = number.replaceAll("[^0123456789]"],""); OK but what if the reader does not know about negation...
idea see article
perfect!!!
Admin
Programming to a whitelist is too hard, plus, it's not secure!
Admin
Admin
The WTF is the requirement "Only the numbers should be saved."
Why would you do that if you don't bother to validate ? You may as well just save the input exactly as given.
Admin
Admin
Easy. Add zero. If it isn't a number you'll get an error.
Admin
True. But the sense of smugness you get from using regexes is priceless.
Admin
Admin
Admin
"Don't think it is Javascript, looks like ruby looking at the comment."
In ruby you use "gsub" for this purpose; "replace" does something a bit different (and fairly pointless).
Admin
Obvious troll is obvious
Admin
Mwahahahahahaha... Beware, looking at the below code may induce vomiting.
oh, and can't forget the foreach-switch...
Admin
F@#)%(*@# you askimet.
why have a shitty capture and then prevent so many legitimate posts?
Implement a proper captcha and get rid of askimet.
Admin
Hint - it's called a telephone NUMBER for a reason. You can draw whatever characters you want on your handset and press those until your finger tips wear away, but the number is still a number.
Admin
Note also that the code calls replace so many time that regex performance issues pale in comparison.
Admin
Admin
Are you one of those guys who spends 3 days finding a 'clever' workaround to save 2 clock cycles for a task which is called once an hour and has a disk/network bottleneck anyway?
This is precisely the type of task for which a regex should be used. Seriously Expensive is a relative term, and given the context of this system - no it isn't.
Admin
A Møøse once bit my sister ... No realli!
Admin
Obviously you should have put each character into a string array and used String.Join to make the final string.
Maybe even writing your own linked list class and dropping in some unsafe code with pointers in there.
This is not spam. Akismet can kiss my ass.
Admin
Where is death when we need it !
Admin
It's here, in the form of Akismet.
Admin
No, that would be too 'enterprisey'... You need to show an absolute lack of understanding with both gerenal concepts and of the language specific usage/functions.
You want to show someone lifting a car with their bare hands to change a tire, not them building an elevator out of bubble-gum and sticks.
Admin
Paid by the character...
Admin
Apparently he didn't know how to use functions, either.
I love seeing code in triplicate. I love seeing code in triplicate. I love seeing code in triplicate.
Admin
Admin
I love how he even managed to miss the OBVIOUS standard ASCII characters:
',_{}|"?
He couldn't even manage to write bad code :(
DaveE
Admin
You forgot OnError, ResumeNext. And you're going to need that because VB strings are 1 based!
The real WTF etc etc...
Admin
What do you mean? That code looks like it was auto-generated...
Admin
I'd love to see a full 16-bit Unicode compliant version of this code. And one compatible with escaped unicode and escaped HTML...and escaped HTML Unicode.