• Zygo (unregistered) in reply to rbonvall
    rbonvall:
    GordonB:
    With a regular expression.

    Shhhh, don't mention it. Now someone will quote Zawinski.

    OK...

    Jamie Zawinski <[email protected]>:
    X Windows is to graphics hacking as roman numerals are to the square root of pi.
  • (cs) in reply to LiquidPT
    LiquidPT:
    Spectre:
    The real WTF is that they first set the label visibility, and then text, which leads to unnesessary flickering.

    Not if this is server-side C# code...

    Gah! My bad, so nevermind.

  • Andrew (unregistered)

    This looks very VB to me. VB isn't bad, but there are alot of bad VB programmers.

    C too hard C++ too hard Java too hard oh wait, here's a language I can figure out.

    I hate VB not because of the language. Its because of all the BS artist that claim they can program in it.

  • Bob (unregistered) in reply to meh
    meh:
    Sandy:
    The real wtf is that three spaces is ok.
    If that is the case, what's the false/non-real/unreal wtf?

    The Imaginary WTF is that sqrt(-1) spaces would work...

  • Steve Carter (unregistered)

    I once attempted to write a whole space-invaders game like that.

    10 PRINT " ^" 20 IF INKEY$="O" THEN GOTO 50 30 IF INKEY$="P" THEN GOTO 90 40 GOTO 20 50 PRINT " ^ " 60 IF INKEY$="O" THEN GOTO 130 70 IF INKEY$="P" THEN GOTO 170 80 GOTO 60 90 ...

    But to be fair, I was 11.

  • umm... (unregistered) in reply to Andrew
    Andrew:
    This looks very VB to me. VB isn't bad, but there are alot of bad VB programmers.

    C too hard C++ too hard Java too hard oh wait, here's a language I can figure out.

    I hate VB not because of the language. Its because of all the BS artist that claim they can program in it.

    Why do I not think you're being sarcastic?

  • Jules (unregistered) in reply to ParkinT

    Are you sure this is client-side? It looks like server side ASP.NET. In which case, this should be re-written using an ASP.NET Regular Expression Validator which would run as client-side java script (but also checked on the server side using the Page.IsValid property to ensure that someone hasn't bypassed the client-side validation.

  • Me (unregistered) in reply to FooLman
    FooLman:
    Have you ever checked the requirements? What if it said: invalid input is empty string, or one or two spaces. Everything else should be considered valid. How would you code that? :)

    With a chisel.

    In the author's forehead.

  • OMG (unregistered) in reply to Bob
    [ICR]:
    if(!IsValidInput(txtloginname.Text)) { lblloginMessage.Visible=true; lblloginMessage.Text = "Please Enter the User Id"; return; }
    if(!IsValidInput(txtcompanyname.Text))
    {
        lblloginMessage.Visible=true;
        lblloginMessage.Text = "Please Enter the Company";
        return;
    }
    

    ... }

    public static bool IsValidInput(string text) { return !(text == "" || text == " " || text == " "); }

    Should be:

    ...
        if(!IsValidInput(txtloginname.Text, 'User Id') ||
           !IsValidInput(txtcompanyname.Text, 'Company'))
        {
            return;
        }
    ...
    }
    
    public static bool IsValidInput(string text, string label)
    {
        if (text == "" || text == " " || text == "  "){
            lblloginMessage.Visible=true;
            lblloginMessage.Text = "Please Enter the "+label;
            return false;
        } else {
            return true;
        }
    }
    
    Bob:
    Wow, just wow.... and when the requirements change comes down that companyname has a different rule than loginname, and some weak programmer modifies the isValidInput routine without proper testing.. Wait.. that's next week's WTF..

    Wow, just wow...

  • Bot (unregistered) in reply to Bob
    Bob:
    Wow, just wow.... and when the requirements change comes down that companyname has a different rule than loginname, and some weak programmer modifies the isValidInput routine without proper testing.. Wait.. that's next week's WTF..

    So in your mind all programmers should write crappy code so that crappy programmers won't mess up good code? Doesn't that turn everyone into crappy programmers?

  • anon (unregistered) in reply to FooLman
    FooLman:
    Have you ever checked the requirements? What if it said: invalid input is empty string, or one or two spaces. Everything else should be considered valid. How would you code that? :)
    With comments! Preferably the kind that say what the weird requirements are, and has direct quotes from the emails that asked for such a thing.
  • Bobble (unregistered) in reply to Bot
    Bot:
    Bob:
    Wow, just wow.... and when the requirements change comes down that companyname has a different rule than loginname, and some weak programmer modifies the isValidInput routine without proper testing.. Wait.. that's next week's WTF..

    So in your mind all programmers should write crappy code so that crappy programmers won't mess up good code? Doesn't that turn everyone into crappy programmers?

    That requirement just came down from my lead not 2 hours ago. Luckily I'll have her job in two weeks.

  • tray (unregistered) in reply to anon
    anon:
    FooLman:
    Have you ever checked the requirements? What if it said: invalid input is empty string, or one or two spaces. Everything else should be considered valid. How would you code that? :)
    With comments! Preferably the kind that say what the weird requirements are, and has direct quotes from the emails that asked for such a thing.

    I agree 100% I was just about to say that I only miss the comments, and I am really suprised now that there's someone else who also suggest putting links in comments. I thought that was only my perversion.

  • ci plus plus (unregistered) in reply to jkohen
    jkohen:
    With a loop, of course! (C++ RULZ, VB for kiddidz HA!!!)
    bool b = true;
    for (int i = 0; i < strlen(s); i++) {
     if (s[i] != ' ') {
      b = false;
      goto GOOD; // VERY IMPORTANT 4 SPEED! remove this and puppy die!
     }
    }
    if (b) {
     // \a*3 = VERY laud BEEEP
     return "\a\a\aYou have error!!!\n";
    }
    // Stpuid GCC give error label end of block. I wrote clever trick to shut up compiler.
    GOOD: b = !!b;
    

    I'm afraid that you should have used a functor instead. It's a lot easier to understand and maintenance is a breeze.

    class Validate {
    	bool operator () ( char *s )
    	{
    		int _s = 0;
    		while ( s && *s && _s < 2 ) _s += (' ' == *s++ ? 1 : -_s );
    		return _s < 2 && s;
    	}
    }
    
  • Jonadab (unregistered) in reply to FooLman
    FooLman:
    Have you ever checked the requirements? What if it said: invalid input is empty string, or one or two spaces. Everything else should be considered valid. How would you code that? :)

    die "invalid input: $input" if $input =~ /^ {0,2}$/;

    (No, that's not in the same programming language as the code in the article, but since I don't actually know what programming language the original code was in, I just wrote my answer in my language of choice.)

  • Pedantic (unregistered) in reply to FooLman
    FooLman:
    Have you ever checked the requirements? What if it said: invalid input is empty string, or one or two spaces. Everything else should be considered valid. How would you code that? :)

    public bool IsValid(string text) { // Invalid texts are the empty string, // one space, or two spaces return !(text.Length <= 2) || !(text.Trim() == ""); }

    if(!IsValid(txtloginname.Text)) { lblloginMessage.Visible=true; lblloginMessage.Text = "Please Enter the User Id"; return; }

    if(!IsValid(txtcompanyname.Text)) { lblloginMessage.Visible=true; lblloginMessage.Text = "Please Enter the Company"; return; }

    if(!IsValid(txtchangereason.Text)) { lblloginMessage.Visible=true; lblloginMessage.Text = "Please Enter the Change Reason"; return; }

    Of course, I would probably also condense the three if statements given how repetitive their logic is.

  • Ragea (unregistered)

    Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems.

  • (cs) in reply to Ragea
    Ragea:
    Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems.
    Geez, you could at least attribute this little gem to Jamie Zawinski. It's not like we don't see it every other day on this site.

    (And FTR, this is an obvious case for regexps. And a number of other things -- see above. Nothing wrong with regexps -- they solve problems to do with "strings". It would be nice to think that we're all into higher abstractions than "strings" these days, but ... well ... WTF.)

    XML is not an acceptable higher-level abstraction for "string," incidentally.

  • BillyBob (unregistered) in reply to Jonneh
    Jonneh:
    What is with the Constant Viagra ads?

    Is this industry really plagued by ED? I've only just started out :[

    Don't be too upset... in this industry having problems with the man downstairs makes no difference at all ;-)

  • (cs) in reply to Tobby
    Tobby:
    Sounds like an XKCD moment...

    "This form still accepts spaces! What are we gonna do?!?"

    "Everybody stand back! I know regular expressions!"

    If only we could use these poor individuals in studying raptor attacks.

    Yes it is cruel to the raptors.

  • Kawazoe Masahiro (unregistered)

    Ya ... I seriously think that someone broke your CAPTCHA system ...

  • smash (unregistered) in reply to ci plus plus

    dammit ci plus plus, what do you think you are doing? Your code does not have any GO TO's

  • Colin (unregistered) in reply to akatherder
    akatherder:
    My buddy Darrell " " Simpkins always uses his nickname as his login id on websites. Not sure what he would do here. He's almost as bad as Smitty "Drop Users" Holmes.

    Very funny! Thanks for the good laugh!

  • Bryan (unregistered)

    Is this ActionScript code? It looks like it. ActionScript doesn't have a trim function. Which is probably why this programmer was doing this silliness. Time to make your own trim function.

  • VFrank (unregistered)

    There was such thing in one of my project too! This is really bad code, but we can understand why when you see something like this :

    <input name="loginname" value=" <?= $txtloginname ?>"/>

    Because each time the form is reloaded, a blank is inserted and they want to avoid that. So if the user enter "", it reload with value " ", and then " ", etc.

  • Sean (unregistered)

    { if comment = true } POST {comment} comment Lorem ipsum whatever. } {function VALIDATE true [if]} } endif true SUBMIT [if] }

  • cialis generic (unregistered)
    Comment held for moderation.
  • generic cialis (unregistered)
    Comment held for moderation.

Leave a comment on “What If Someone Types In " "?”

Log In or post as a guest

Replying to comment #:

« Return to Article