Spot The WTF: JavaScript Edition

Started by Darren Dirt, November 01, 2005, 04:57:02 PM

Previous topic - Next topic

Darren Dirt

See how many stupid things YOU can identify in this horrid alphanum-checking code!  :lol:



http://thedailywtf.com/forums/36898/ShowPost.aspx



QuoteIt's time once to play Spot The WTF. You should know the rules by now; just see how many WTF you can find. I counted five. I'd rate the difficulty of today's exercise the same as that of finding the screaming man in Edvard Munch's Scream.




function bfIsAlphaNumeric( cfield )

{

 cfield.value = TRIM2(cfield.value);

 for ( i = 0 ; i < cfield.value.length ; i++)

 {

   var n = cfield.value.substr(i,1);

   if ( n != 'a' && n != 'b' && n != 'c' && n != 'd'

     && n != 'e' && n != 'f' && n != 'g' && n != 'h'

     && n != 'i' && n != 'j' && n != 'k' && n != 'l'

     && n != 'm' && n != 'n' && n != 'o' && n != 'p'

     && n != 'q' && n != 'r' && n != 's' && n != 't'

     && n != 'u' && n != 'v' && n != 'w' && n != 'x'

     && n != 'y' && n != 'z'

     && n != 'A' && n != 'B' && n != 'C' && n != 'D'

     && n != 'E' && n != 'F' && n != 'G' && n != 'H'

     && n != 'I' && n != 'J' && n != 'K' && n != 'L'

     && n != 'M' && n != 'N' && n != 'O' && n != 'P'

     && n != 'Q' && n != 'R' && n != 'S' && n != 'T'

     && n != 'U' && n != 'V' && n != 'W' && n != 'X'

     && n != 'Y' && n != 'Z'

     && n != '0' && n != '1' && n != '2' && n != '3'

     && n != '4' && n != '5' && n != '6' && n != '7'

     && n != '8' && n != '9'

     && n != '_' && n != '@' && n != '-' && n != '.' )

   {

     window.alert("Only Alphanumeric are allowed.\nPlease re-enter the value.");

     cfield.value = '';

     cfield.focus();

   }

   cfield.value =  cfield.value.toUpperCase();

 }

 return;

}




. . . another funny implementation, this time of a "boolean" type (sorta) --> http://thedailywtf.com/forums/47844/ShowPost.aspx
_____________________

Strive for progress. Not perfection.
_____________________