Regex issue with validation

I tried to test the following. Its showing true in the console window. But in the test case…its showing error.

don’t use the g flag with the test method, it moves the index at which the test is started, and so the test fail in unexpected ways