0

I have some regex patterns in an object literal which I would like to switch over when I look for certain patters like security numbers.

Why do I get a match on abc below?

Simplified version of my code:

var cst = {
    SECURITYNUMBER: /^\d{12}$/
};

function doStuff(query){

    $.each(query.split(' '), function(i, word){

        switch(true){
            case new RegExp(cst.SECIRUTYNUMBER).test(word): 
                console.log('match');
                break;
        }

    });
}

doStuff('198610054937 abc');

http://jsfiddle.net/t1ps0vdh/

0

1 Answer 1

1

You've got a typo... instead of using SECURITYNUMBER, you've used SECIRUTYNUMBER.

Change...

case new RegExp(cst.SECIRUTYNUMBER).test(word): 

To...

case new RegExp(cst.SECURITYNUMBER).test(word):

http://jsfiddle.net/t1ps0vdh/1/

Sign up to request clarification or add additional context in comments.

1 Comment

I know the feeling @Johan, just needed a 2nd pair of eyes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.