Converting integers to English words The goal of this code golf is to convert integers to English words.  

The program prompts for input. If this input isn't an integer, print NaN. If it is an integer, convert it to English words and print these words. Minimum input: 0 (zero). Maximum input: 9000 (nine thousand).
So, 5 returns five (case doesn't matter), and 500 returns five hundred or five-hundred (dashes don't matter).  

Some other rules: 

A one before hundred or thousand is optional: one hundred is correct, but hundred too (if the input is 100 of course).

The word and in for example one hundred and forty five is optional too.

Whitespace matters. So, for 500, five-hundred or five hundred is correct, but fivehundred is not.

Good luck!
JavaScript (375)

Probably a terrible attempt, but anyway, here goes...

alert(function N(s,z){return O="zero,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thir,,fif,,,eigh,,,,twen,,for".split(","),(z?O[s]||O[s-10]||O[s-20]:s&lt;13?N(s,1):s&lt;20?N(s,1)+"teen":s&lt;100?N(a=20+(s/10|0),1)+"ty"+(s%10?" "+N(s%10):""):s&lt;1e3?N(s/100|0)+" hundred"+(s%100?" "+N(s%100):""):s&lt;1e5?N(s/1e3|0)+" thousand"+(s%1e3?" "+N(s%1e3):""):0)||NaN}(prompt()))


Pretty-printed (as a function):

function N(s,z) {
  return O = "zero,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thir,,fif,,,eigh,,,,twen,,for".split(","),
      (z? O[s] || O[s-10] || O[s-20]
       : s &lt; 13?  N(s,1)
       : s &lt; 20?  N(s,1) + "teen"
       : s &lt; 100? N(a=20+(s/10|0),1) + "ty" + (s%10?" "+N(s%10):"")
       : s &lt; 1e3?  N(s/100|0) +  " hundred" + (s%100?" "+N(s%100):"")
       : s &lt; 1e5?  N(s/1e3|0) + " thousand" + (s%1e3?" "+N(s%1e3):"") : 0) || NaN
}


Sample conversion (note that it even outputs NaN when out of bounds, i.e. invalid input):

540: five hundred forty
4711: four thousand seven hundred eleven
7382: seven thousand three hundred eighty two
1992: one thousand nine hundred ninety two
hutenosa: NaN
1000000000: NaN
-3: NaN