Package /org/apache/commons/validator/javascript

validateUtilities.js

Summary

No overview generated for 'validateUtilities.js'


Method Summary
static Object isAllDigits(argvalue)
           Check a value only contains valid numeric digits
static Object isDecimalDigits(argvalue)
           Check a value only contains valid decimal digits
static Object retrieveFormName(form)
           Retreive the name of the form

    /*$RCSfile: validateUtilities.js,v $ $Rev: 330243 $ $Date: 2005-11-02 12:26:02 +0000 (Wed, 02 Nov 2005) $ */

  /**
  * This is a place holder for common utilities used across the javascript validation
  *
  **/

  /**
   * Retreive the name of the form
   * @param form The form validation is taking place on.
   */
  function retrieveFormName(form) {

      // Please refer to Bugs 31534, 35127, 35294 & 37315
      // for the history of the following code

      if (form.getAttributeNode) {
          if (form.getAttributeNode("id") && form.getAttributeNode("id").value) {
              return form.getAttributeNode("id").value;
          } else {
              return form.getAttributeNode("name").value;
          }
      } else if (form.getAttribute) {
          if (form.getAttribute("id")) {
              return form.getAttribute("id");
          } else {
              form.attributes["name"];
          }
      } else {
          if (form.id) {
              return form.id;
          } else {
              return form.name;
          }
      }

  }  

  /**
   * Check a value only contains valid numeric digits
   * @param argvalue The value to check.
   */
  function isAllDigits(argvalue) {
      argvalue = argvalue.toString();
      var validChars = "0123456789";
      var startFrom = 0;
      if (argvalue.substring(0, 2) == "0x") {
         validChars = "0123456789abcdefABCDEF";
         startFrom = 2;
      } else if (argvalue.charAt(0) == "0") {
         validChars = "01234567";
         startFrom = 1;
      } else if (argvalue.charAt(0) == "-") {
          startFrom = 1;
      }

      for (var n = startFrom; n < argvalue.length; n++) {
          if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
      }
      return true;
  }

  /**
   * Check a value only contains valid decimal digits
   * @param argvalue The value to check.
   */
  function isDecimalDigits(argvalue) {
      argvalue = argvalue.toString();
      var validChars = "0123456789";

      var startFrom = 0;
      if (argvalue.charAt(0) == "-") {
          startFrom = 1;
      }

      for (var n = startFrom; n < argvalue.length; n++) {
          if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
      }
      return true;
  }

Package /org/apache/commons/validator/javascript

Copyright ¬ 2000-2005 - Apache Software Foundation
Documentation generated by JSDoc on Wed Nov 16 02:51:00 2005