I need to verify that an input is between 1 and 512 characters long. I'm using the standard length-check regex of /^.{1,512}$/
. When I run
/^.{1,512}$/.test(null)
it returns true. How do I get a length-check regex to fail against null? And why does this test true against null in the first place?
EDIT: Leaving this here since it's more googleable in my case than the earlier question, but per here, the problem is that the regex coerces null into 'null' before testing.