Functions That Return Values Can Be Used in Expressions : Function : Language Basics JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Language Basics » Function »

 

Functions That Return Values Can Be Used in Expressions




/*
JavaScript Unleashed, Third Edition
by Richard Wagner and R. Allen Wyke 

ISBN: 067231763X
Publisher Sams CopyRight 2000

*/


<html>
<head>
  <title>JavaScript Unleashed</title>
  <script type="text/javascript">
  <!--
    function isPhone(aString) {
      var aChar = null;
      var status = true;
      if(aString.length != 13) {
        status = false;
      }else{
        for(var i = 0; i <= 12; i++) {
          aChar = aString.charAt(i);
          if i == && aChar == "(" ){
            continue;
          }else{
            ifi == && aChar == ")" ){
              continue;
            }else{
              ifi == && aChar == "-" ){
                continue;
              }else{
                ifparseInt(aChar,10>= && parseInt(aChar,10<= ){
                  continue;
                }else {
                  status = false;
                  break;
                }
              }
            }
          }
        }
      }
      return(status);
    }
  // -->
  </script>
</head>
<body>
  <script type="text/javascript">
  <!--
    var userInput = "(800)555-1212";    
    
    if(isPhone(userInput)) {
      document.writeln("Thank you for your phone number.");
      document.writeln("I will have a representative get you");
      document.writeln("more information.");
    }else{
      document.writeln("Please re-enter your phone number");
      document.writeln("using the format (###)###-####");
    }
  //-->
  </script>
   
</body>
</html>

           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Language Basics
» Function