topical media & game development

talk show tell print

basic-javascript-08-ch8-examp2.htm / htm



  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
  <html>
  <head>
  <title>Example</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  </head>
  <body>
  <script language="JavaScript" type="text/JavaScript">
  function regExpIs_valid(text)
  {
     var myRegExp = /[^a-z\d ]/i;
     return !(myRegExp.test(text));
  }
  function butCheckValid_onclick()
  {
     if (regExpIs_valid(document.form1.txtPhrase.value) == true)
     {
        alert("Your passphrase contains only valid characters");
     }
     else
     {
        alert("Your passphrase contains one or more invalid characters");
     }
  }
  </script>
  <form name=form1>
  Enter your passphrase:
  <br>
  <input type="text" name=txtPhrase>
  <br>
  <input type="button" value="Check Character Validity" name=butCheckValid
     onClick="butCheckValid_onclick()">
  </form>
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.