Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery if found in string

How can I have jQuery check to see if the content of a variable contains a specific word and have it execute an alert if matched?

like image 556
Ronal Avatar asked Aug 17 '09 13:08

Ronal


1 Answers

if( str.indexOf( "your word" ) !== -1 )

or

if( str.search( /your regex/ig ) )

or

if( str.match( /your regex/ig ).length > 0 )

As it shows, you do not need jQuery to solve this problem.

But, hell, why not use jQuery selectors if you want:

$('#someId:contains(text)')
like image 138
geowa4 Avatar answered Sep 29 '22 17:09

geowa4