- 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
Brillant!
Admin
First......
Admin
NOT!
Admin
var comment = new RegExp(/^(W|w)(T|t)(F|f)|(W|w).(T|t).(F|f).$/);
Admin
You call that a regular expression? This is a regular expression!
Admin
That's not a regex that's a string!
Admin
Looks like someone wanted to use RegEx but didn't know what it's for.
Admin
But Regular Expressions work so much better! I'm sure the boss said something like "Gidday mate! Why don't you just use a regex to filter out Australians!"
Admin
Well, that's different a different way to do it.
Admin
Fail. No multithreading.
Admin
RegEx.... Austrailian for String
Admin
Fail for no XML
Admin
I like how they tell customer to visit the exact same site if they enter australia as a country. A clueless user could enter some kind of infinite loop and try to book forever.
Admin
Forgot to check for "OZ".
Admin
But what about testing for "Orstrylya"?
Admin
No, I don't know what it means either.
Admin
There are at least 2 WTFs here. First, that what they've written could have been written a lot more succinctly (the regex should be marked case-insensitive, and even for a developer unaware of that option it could be written much more simply than that....). Second, what the code actually does is probably a bad idea in the first place. (A drop-down box for the country might work better than trying to parse entered country names, with either a prompt disallowing Australia and New Zealand, or just not putting them there in the first place; but even then, what they're trying to accomplish is probably not a good idea, especially as a drop-down box has usability problems of its own.) Other potential WTFs here (as in, almost certainly a WTF, but there isn't enough information in the article to tell): if that validation code isn't duplicated server-side, or if the server-side validation code has the same, or a different, bug; and is there a good reason to not just process the info as if it had been entered in the other website (or auto-redirect to the other website, or just not have two websites at all)?
Admin
Dang no check for a dingo.
captcha: vulputate - A masturbating vulture?
trwtf: posting STILL isn't fixed Alex quit writing columns for Dev Disasters and fix this board!
Admin
Well I guess they never heard about the /i qualifier.... ;-)
Besides, how many ways are there to spell Australia using 'funny' characters as substitutes to fool this check (or just plain spelling errors)????
Yours yazeran
Plabn: To go to Mars one day with a hammer.
Admin
Since when is New Zealand not outside Australia? Must be pretty much hated by the Kiwis, that site.
Admin
"Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems."
Admin
And what if the bloke enters "shenanigans"?
Admin
Now please can we be done with quoting famous people without giving them proper credit? Pretty please.
Admin
That regex should go straight to the poolroom.
Obviously the developer is an ideas man.
(Tell him he's dreaming).
http://www.youtube.com/watch?v=TM-GVRvsZrA
Admin
"Regular expressions are neither"
I am sure someone will explain this as well.
Admin
Why use a regex? It's so inefficient for finding what's effectively a known quantity. They're not searching for any string, they're searching for a particular one. Sure, there's some permutations with capitalization, but those can be checked for with some hard coded values. As long as you put them in the right order, they index search will be faster than the initialization of the regex engine.
if (inputbox.value == "australia") alert ("You cannot be in australia"); else if (inputbox.value == "australiA") alert ("You cannot be in australiA"); else if (inputbox.value == "australIa") alert ("You cannot be in australIa"); else if (inputbox.value == "australIA") alert ("You cannot be in australIA"); else if (inputbox.value == "austraLia") alert ("You cannot be in austraLiA");
etc. Nothing a bit of copy'n'paste (or Excel manipulating) can't produce in less time than mucking with a regex could.
Admin
Thanks for clarifying that, "Not JWZ".
Admin
Balderdash! var validator = new RegExp( /^(A|a)(U|u)(S|s)(T|t)(R|r)(A|a)(L|l)(I|i)(A|a) |(N|n)(E|e)(W|w)(Z|z)(E|e)(A|a)(L|l)(A|a)(N|n)(D|d) |(N|n)(E|e)(W|w) (Z|z)(E|e)(A|a)(L|l)(A|a)(N|n)(D|d)$/);
should be taken out as a global variable in case someone tries to repeatedly make a booking from Australia!
Admin
Sounds legit.
Admin
He's going about this all wrong. Instead, the code should test for every other country in the world, and let those pass. That way you can't submit with Austarlia or NewZaeland
Admin
Hmmmm.
It needs XPath!
Admin
Good idea, but the array of strings that could be other countries might be a bit too big to test in a for-switch.
captcha is "plaga": Spanish for plague.
Admin
Umm...No? Did you read the article?
Admin
Ohh, now I get the WTF. They did this:
When they could've done this:
Admin
TRWTF is all the people using pseudo Australian slang.
Admin
i dont even know
Admin
Argh! Would you people please stop making bizarre associations between anything latin or latin-like with something sexual.
If you don't know, search for it. You are on the \b\w*(ing|ed)?\b internet.
Admin
They should have just reported their international site to Australia's government censorship board, and let the ISPs do the work.
Admin
...what I want to say?
Admin
This is the reason why devs should be banned from using JavaScript for anything other than field validation, and even then the validation should also be done server-side.
This regexp doesn't qualify as "validation". Let's see how it gets bypassed by "New Zealand"! :)
Addendum (2009-10-05 11:11): Meh, this thing ate the extra spaces ... I meant "New[space][space]Zealand"!!!
Admin
Admin
Sorry, I thought we were offering up ridiculous ideas here today.
Admin
And it might be necessary to check for all the misspellings the country names may have in english and every other language, including esperanto.
Admin
Why do a stach of ifs?
Convert the string to al lowercase, than do a single if.
Admin
Simple, we put them in a database and then get retrieve them as XML via a web service and use that to dynamically generate a giant if/else if construct to check for countries that are allowed to pass. If more countries are created later, you can simply update the database and everything is taken care of.
Admin
<sarcasm>Genius! I can't imagine why nobody else has suggested that yet!</sarcasm>
Admin
Allowing textfields for country could bring on interesting results... wonder if someone would put "Sealand" or "Lizbekistan" there...
Admin
Alternate solution: ask the Powers Below to add the site to the Great Australian Firewall list of blocked sites...
Admin
Meh, depends on if they get better deals that way. Speaking as a Canadian, I can tell you that on a website that provides or sells services or products, 99% of the time I'd rather Canada be included as part of the States. (Hulu, Amazon, and on, and on).
Admin
No? Because the error tells them to visit *.com.au and that is the AU equivalent of *.com or *.us (similar to *.co.uk for commercial websites in the UK).
Someone made a typo in the actual article, tho, because it's missing the required ".com" in the ".au" domain.
I hate it when people see a mistake in the article, get all worked up on it and then don't double-check before posting.