Page 1 of 1

Testing for characters in JS string

Posted: Sat Jun 21, 2003 12:57 pm
by mzfp2
simple question using JavaScript, how can i determine if a string contains certain characters, eg qoutes or asterisks?

Posted: Sat Jun 21, 2003 1:43 pm
by patrikG
use regEx - yes, i know it's a fantastic pain in the b**t that you can even do them in JS, but hey: it's been certified as a good thing, even Bill Gates and Richard Stallman do the regEx-jiggle together.

Coming back to your question: use Javascript's search (don't have a link to a tutorial for that, but have a look at the following example)

Code: Select all

<html><head><title>Test</title>
</head><body>
<script type="text/javascript">
<!--
 var Aussage = "Hello there, sky is blue, sun is bright, life is just like dynamite.";
 var Ergebnis = Aussage.search(/dynamite.+/);
 if(Ergebnis != -1)
  alert("found");
//-->
</script>
</body></html>