How can I match a whole word in JavaScript?
Use the word boundary assertion \b
:
/\bme\b/
To use a dynamic regular expression see my updated code:
new RegExp("\\b" + lookup + "\\b").test(textbox.value)
Your specific example is backwards:
alert((/\b(2)\b/g).test(lookup));
Regexpal
Regex Object