Detect if certain text is in a variable

Rodrigo Costa
Rodrigo Costa used Ask the Experts™
on
Hi folks, I need to findout if a certain text was typed in a certain variable, for example a form send to my script a variable named "URL", in this variable the user had to have typed an url for a certain file they should have in their server, what I want is a way to find out if in this variable they typed "for123" in the variable, it could be in the beggining, in the middle or at the end, but I would need to know it and I can't seem to find a way to do this...

Any help would be appreciated.

Cheers!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jon NormanInformation Systems Manager
Top Expert 2012

Commented:
in javascript:

if(variableName.match(/for123/)){
  alert("matched");
}else{
  alert("not matched");
}

Open in new window


where variableName is the variable.
Information Systems Manager
Top Expert 2012
Commented:
or if case doesn't matter - e.g. FoR123 is also ok:

if(variableName.match(/for123/i)){
  alert("matched");
}else{
  alert("not matched");
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial