commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Craviotto" <mcravio...@ec.gba.gov.ar>
Subject Question about Validator and Javascript
Date Thu, 06 Nov 2003 14:54:02 GMT
Hello,

   First anything sorry about my english. I speak Spanish.

 

I don't find documentation about how to write javascript validation,  I
find many examples which uses javascript, but I need more information
about how this works. 

For example :

 

 

          function validateCuit(form) { 

                var bValid = true;

                var focusField = null;

                var i = 0;

                var fields = new Array();

                oRange = new validCuit();

                for (x in oRange) {

                    if ((form[oRange[x][0]].type == 'text' ||

                         form[oRange[x][0]].type == 'textarea') &&

                        (form[oRange[x][0]].value.length > 0)) {

                        var fStrCuit = form[oRange[x][0]].value;

                        var strPrefijo = fStrCuit.substr(0,2);

                        var strNumero = fStrCuit.substr(3,8);

                        var strDigito = fStrCuit.substr(12,1);

                        //el mumero no puede ser cero

                        var strNumero_aux = strNumero;

                        var h = 0;

                        while((strNumero_aux.charAt(0) == 0) && (h<7)){

                          strNumero_aux = strNumero_aux.substr(1,
strNumero_aux.length - 1);

                          h++;

                        }

                        if(parseInt(strNumero_aux) == 0){

                          if (i == 0) {

                                focusField = form[oRange[x][0]];

                            }

                            fields[i++] = oRange[x][1];

                            bValid = false;                          

                        }

                        // Validacion prefijo

                        if ( (strPrefijo != "20") & (strPrefijo != "23")
& (strPrefijo != "24") & (strPrefijo != "27") & 

                             (strPrefijo != "30") & (strPrefijo != "33")
& (strPrefijo != "34") ){ 

                           if (i == 0) {

                                focusField = form[oRange[x][0]];

                            }

                            fields[i++] = oRange[x][1];

                            bValid = false;

                       } else {

                      // Validacion digito verificador

                      var valDigCuit, valDigConstant;

                      var strConstant = "54327654321";

                      var strCuit = strPrefijo + strNumero + strDigito;

                      var valPos = 0;

                      var valResult = 0;

                      do {

                       valDigCuit = parseInt(strCuit.substr(valPos,1));

                       valDigConstant =
parseInt(strConstant.substr(valPos,1));

                       valResult = valResult + (valDigCuit *
valDigConstant);

                       valPos = valPos + 1; 

                      }

                      while (valPos < 11);

                       if ( (valResult % 11) != 0 ){

                           if (i == 0) {

                                focusField = form[oRange[x][0]];

                       }

                       fields[i++] = oRange[x][1];

                       bValid = false;

                      }

                      }

                    }   

                  } 

                  if (fields.length > 0) {

                  focusField.focus();

                  alert(fields.join('\n'));

                  }

                  return bValid;  

               }]]>

         </javascript>  

      </validator>

 

but I don't understood what is  form[oRange[x][0]] for example ?? 

 

Can you send me documentation or places (url) where I can find
documentation than help me to resolve my problems. ?? Thank you very
much.


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message