Get a substring index : indexOf « String « JavaScript Tutorial






<HTML>
<HEAD>
<SCRIPT language="JavaScript">
<!--
function myFunction()
{
   var email_add=window.prompt("What is your e-mail address?","");
   if (email_add.indexOf("@") == -1)
   {
      window.alert("You need an '@' symbol in your address, please try again.");
   }
   if (email_add.indexOf(".") == -1)
   {
      window.alert("You need a '.' symbol in your address, please try again.");
   }
   if ( (email_add.indexOf("@") != -1) && (email_add.indexOf(".") != -1) )
   {
      document.write("Thanks!");
   }
}
//-->
</SCRIPT>
</HEAD>
<BODY>

<FORM>
<INPUT type="button" value="Click to enter an e-mail address" onClick="myFunction();">
</BODY>
</HTML>








6.16.indexOf
6.16.1.String.indexOf()
6.16.2.Get a substring index
6.16.3.Use indexOf method the search a substring