Javascript to match a specific number using regular expressions

Posted by ren33 on Stack Overflow See other posts from Stack Overflow or by ren33
Published on 2010-05-07T20:05:10Z Indexed on 2010/05/07 20:08 UTC
Read the original article Hit count: 529

Filed under:
|
|
|
|

I was using javascript to detect for specific key strokes and while writing the method I thought I'd try regular expressions and the test() method and came up with:

if (/8|9|37|38|46|47|48|49|50|51|52|53|54|55|56|57|96|97|98|99|100|101|102|103|104|105|110/.test(num)) {
    // do something if there's a match
}

This doesn't seem to work 100% as some values seem to make it past the regex test, such as 83. I've since moved on, but I'm still curious as to why this didn't work.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regular