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').


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


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}$/


Fork me on GitHub