Click to See Complete Forum and Search --> : Like Function


webdev1
04-07-2003, 08:12 AM
I'm sure this is probably a very basic JS thing I should already know, but I've never had to use it before, so I apologize in advance for my ignorance. Does anyone know what the syntax is for 'like' or 'contains'? i.e. if (myvar like '***') OR if (myvar contains '***'). I'm assuming it's similar to (if not the same as) C++ but I haven't done that in years, I only recall (i think) using %. If anyone can help me out, I'd appreciate it. Thanks so much!

pyro
04-07-2003, 08:15 AM
Perhaps you are looking for this:

if (myvar == "****")
{
// code here
}

webdev1
04-07-2003, 08:17 AM
No, thats not it. My variable is for an acount number (i.e. ****1234) in a text box, and I need to see if they entered a new one (all nos w/o the ***) but I specifically need to find out if the variable contains the ***s.

SniperX
04-07-2003, 08:21 AM
Im not to sure - but this might work

function checkStar() {
var string = document.form.acc_num.value();
for(var i=0; i<4; i++)
if (string.charAt(i) == '*') {
return true;
}
else {
return false;
}
}

where 4 is the number of stars you are checking,
and 0 is the start position

if it returns true then continue to the next function else let the user try again...

Regards
SniperX