Javascript RegEx Not Working

Viewed 54565

I have the following javascript code:

    function checkLegalYear() {
        var val = "02/2010"; 

        if (val != '') {
           var regEx = new RegExp("^(0[1-9]|1[0-2])/\d{4}$", "g");

            if (regEx.test(val)) {
               //do something
            }
            else {
               //do something
            }
        }
    }

However, my regEx test always returns false for any value I pass (02/2010). Is there something wrong in my code? I've tried this code on various javascript editors online and it works fine.

1 Answers
Related