created by Brian LeRoux & Andrew Lunny. sparodically uncurated by David Trejo.

2013 02 28 null, undefined and test

Checking a variable for one word with one to ten letters lowercase only?

Try this regular expression: /^[a-z]{1,10}$/.test('wakaluba').

    /^[a-z]{1,10}$/.test(null);
    /^[a-z]{1,10}$/.test(undefined);

Both should obviously fail, but return true. srsly, WTF JS?

@damienklinnert

This happens because regex.test() converts its parameter to a string:

    String(null) // "null"

The string "null" matches the regular expression /^[a-z]{1,10}$/

@stevendesu

Fork me on GitHub