commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rlel...@apache.org
Subject cvs commit: jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript validateRequired.js validateMask.js
Date Sun, 18 May 2003 21:36:06 GMT
rleland     2003/05/18 14:36:06

  Added:       validator/src/javascript/org/apache/commons/validator/javascript
                        validateRequired.js validateMask.js
  Log:
  Add Javascript validations for Required and Mask
  
  Revision  Changes    Path
  1.1                  jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateRequired.js
  
  Index: validateRequired.js
  ===================================================================
  
      function validateRequired(form) {
          var isValid = true;
          var focusField = null;
          var i = 0;
          var fields = new Array();
          oRequired = new required();
          for (x in oRequired) {
              var field = form[oRequired[x][0]];
  
              if (field.type == 'text' ||
                  field.type == 'textarea' ||
                  field.type == 'file' ||
                  field.type == 'select-one' ||
                  field.type == 'radio' ||
                  field.type == 'password') {
  
                  var value = '';
                  // get field's value
                  if (field.type == "select-one") {
                      var si = field.selectedIndex;
                      if (si >= 0) {
                          value = field.options[si].value;
                      }
                  } else {
                      value = field.value;
                  }
  
                  if (value == '') {
  
                      if (i == 0) {
                          focusField = field;
                      }
                      fields[i++] = oRequired[x][1];
                      isValid = false;
                  }
              }
          }
          if (fields.length > 0) {
             focusField.focus();
             alert(fields.join('\n'));
          }
          return isValid;
      }
  
  
  1.1                  jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateMask.js
  
  Index: validateMask.js
  ===================================================================
  
      function validateMask(form) {
          var isValid = true;
          var focusField = null;
          var i = 0;
          var fields = new Array();
          oMasked = new mask();
          for (x in oMasked) {
              var field = form[oMasked[x][0]];
  
              if ((field.type == 'text' ||
                   field.type == 'textarea') &&
                   (field.value.length > 0)) {
  
                  if (!matchPattern(field.value, oMasked[x][2]("mask"))) {
                      if (i == 0) {
                          focusField = field;
                      }
                      fields[i++] = oMasked[x][1];
                      isValid = false;
                  }
              }
          }
  
          if (fields.length > 0) {
             focusField.focus();
             alert(fields.join('\n'));
          }
          return isValid;
      }
  
      function matchPattern(value, mask) {
         return mask.exec(value);
      }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message