homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

if statement wildcard

 3:35 pm on Feb 19, 2009 (gmt 0)

Basically Im wondering how to go about using a wildcard in an if statement.

Example being:

function blah()
var something="thisisatopsecretmessage"
if (something==*secret*)
document.write("Found Secret")
document.write("No Secret Found")

I know this is no doubt very basic, but how would I go about changing the if so its basically 'If something has secret in it, do this, else, do that'.



 3:39 pm on Feb 19, 2009 (gmt 0)

You'll need to use Regular Expressions -


 5:49 pm on Feb 19, 2009 (gmt 0)

Or, you could use the indexOf function.

if (something.indexOf("secret") > -1)

indexOf returns the location of the first occurance of the string "secret" within something. If it's not found, it returns -1.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved