Welcome to WebmasterWorld Guest from 54.163.49.19

Forum Moderators: open

Message Too Old, No Replies

if statement wildcard

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

New User

5+ Year Member

joined:Jan 12, 2009
posts:10
votes: 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")
}
else
{
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)

New User

5+ Year Member

joined:Feb 19, 2009
posts:2
votes: 0


You'll need to use Regular Expressions -
[w3schools.com...]
5:49 pm on Feb 19, 2009 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4966
votes: 10


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.