I am trying to validate Canadian ZIP codes using a regex in JavaScript.
This is my code:
var RegEx = new RegExp("/^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d/");
console.log(RegEx.test("G0A 1L0"));
I get false
even though the ZIP code is valid. What's wrong with my regex?