views:

26

answers:

1

Hi, I want the simplest way to check if an underscore (_) is in a variable using jQuery and do something if is not..

if ( '_ is not in var') {
   // Do
}

Thanks!

+1  A: 
var str = "i am a string with _";
if (str.indexOf('_') == -1) {
   // will not be triggered because str has _..
}

and as spender said below on comment, jQuery is not a requirement.. indexOf is a native javascript

Reigel
It's probably important to highlight to OP that the solution does not require jQuery, as demonstrated.
spender
Its worth noting that this isn't jQuery but basic javascript so could be used even without jQuery being loaded. The answer is correct of course, just a noteworthy addition given the question.
Chris