Visualizzazione dei risultati da 1 a 7 su 7
  1. #1

    controllo codice fiscale da aggiungere a classe


    Per la velizione dei form uso un file JS molto comodo, questo il link per visualizzarlo:
    http://www.nextou.it/validation.js

    Dopo l'inclusione del file nella pagina, il tutto viene applicato nel seguente modo (esempio)
    codice:
    <form name="pippo">
    <input type="text" name="nome">
    </form>
    <script language="JavaScript" type="text/javascript">
    var frmvalidator = new Validator("pippo");
    validator.addValidation("nome","req","Inserire il proprio nome");
    </script>
    Molto comodo, è possibile controllare se un campo è tipo "email" allora controllare @ .it etc... la lunghezza di quanti caratteri inseriti, se un campo deve essere solo numerico etc...

    -----------------------------------
    Mi piacerebbe aggiungerci il controllo per il codice fiscale in pase a nome cognome data di nascita comune precedentemente inseriti

    -----------------------------------
    :berto:
    Tanto...lo fanno tutti... posso farlo anche io vero?

  2. #2
    Il validator l'hai fatto tu?

    Se si ti conviene scriverci il nome dell'autore ed aggiungerci una licenza GPL o GPL2 (o se proprio la MIT)

    Comunque, ti basterebbe modificare la funzione V2validateData:

    Codice PHP:
    function V2validateData(strValidateStr,objValue,strError

        var 
    epos strValidateStr.search("="); 
        var  
    command  ""
        var  
    cmdvalue ""
        if(
    epos >= 0
        { 
         
    command  strValidateStr.substring(0,epos); 
         
    cmdvalue strValidateStr.substr(epos+1); 
        } 
        else 
        { 
         
    command strValidateStr
        } 
        switch(
    command
        { 
            case 
    "req"
            case 
    "required":{ 
                
               if (
    objValue.type=="checkbox") {
                    if (
    objValue.checked == false
                    { 
                                    if(!
    strError || strError.length ==0
                                    { 
                                        
    strError objValue.name " : Required Field"
                                    }
    //if 
                                    
    alert(strError); 
                                    return 
    false
                             }
    //if 
               
    } else {            
                       if(eval(
    objValue.value.length) == 0
                       { 
                          if(!
    strError || strError.length ==0
                          { 
                            
    strError objValue.name " : Required Field"
                          }
    //if 
                          
    alert(strError); 
                          return 
    false
                       }
    //if 
              
    }
               break;             
             }
    //case required 
            
    case "maxlength"
            case 
    "maxlen"
              { 
                 if(eval(
    objValue.value.length) >  eval(cmdvalue)) 
                 { 
                   if(!
    strError || strError.length ==0
                   { 
                     
    strError objValue.name " : "+cmdvalue+" characters maximum "
                   }
    //if 
                   
    alert(strError "\n[Current length = " objValue.value.length " ]"); 
                   return 
    false
                 }
    //if 
                 
    break; 
              }
    //case maxlen 
            
    case "minlength"
            case 
    "minlen"
               { 
                 if(eval(
    objValue.value.length) <  eval(cmdvalue)) 
                 { 
                   if(!
    strError || strError.length ==0
                   { 
                     
    strError objValue.name " : " cmdvalue " characters minimum  "
                   }
    //if               
                   
    alert(strError "\n[Lunghezza attuale = " objValue.value.length " ]"); 
                   return 
    false;                 
                 }
    //if 
                 
    break; 
                }
    //case minlen 
            
    case "alnum"
            case 
    "alphanumeric"
               { 
                  var 
    charpos objValue.value.search("[^A-Za-z0-9]"); 
                  if(
    objValue.value.length &&  charpos >= 0
                  { 
                   if(!
    strError || strError.length ==0
                    { 
                      
    strError objValue.name+": Only alpha-numeric characters allowed "
                    }
    //if 
                    
    alert(strError "\n [Error character position " + eval(charpos+1)+"]"); 
                    return 
    false
                  }
    //if 
                  
    break; 
               }
    //case alphanumeric 
            
    case "num"
            case 
    "numeric"
               { 
                  var 
    charpos objValue.value.search("[^0-9]"); 
                  if(
    objValue.value.length &&  charpos >= 0
                  { 
                    if(!
    strError || strError.length ==0
                    { 
                      
    strError objValue.name+": Only digits allowed "
                    }
    //if               
                    
    alert(strError "\n [Error character position " + eval(charpos+1)+"]"); 
                    return 
    false
                  }
    //if 
                  
    break;               
               }
    //numeric 
            
    case "alphabetic"
            case 
    "alpha"
               { 
                  var 
    charpos objValue.value.search("[^A-Za-z]"); 
                  if(
    objValue.value.length &&  charpos >= 0
                  { 
                      if(!
    strError || strError.length ==0
                    { 
                      
    strError objValue.name+": Only alphabetic characters allowed "
                    }
    //if                             
                    
    alert(strError "\n [Error character position " + eval(charpos+1)+"]"); 
                    return 
    false
                  }
    //if 
                  
    break; 
               }
    //alpha 
            
    case "alnumhyphen":
                {
                  var 
    charpos objValue.value.search("[^A-Za-z0-9\-_]"); 
                  if(
    objValue.value.length &&  charpos >= 0
                  { 
                      if(!
    strError || strError.length ==0
                    { 
                      
    strError objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"
                    }
    //if                             
                    
    alert(strError "\n [Error character position " + eval(charpos+1)+"]"); 
                    return 
    false
                  }
    //if             
                
    break;
                }
            case 
    "email"
              { 
                   if(!
    validateEmailv2(objValue.value)) 
                   { 
                     if(!
    strError || strError.length ==0
                     { 
                        
    strError objValue.name+": Enter a valid Email address "
                     }
    //if                                               
                     
    alert(strError); 
                     return 
    false
                   }
    //if 
               
    break; 
              }
    //case email 
            
    case "lt"
            case 
    "lessthan"
             { 
                if(
    isNaN(objValue.value)) 
                { 
                  
    alert(objValue.name+": Should be a number "); 
                  return 
    false
                }
    //if 
                
    if(eval(objValue.value) >=  eval(cmdvalue)) 
                { 
                  if(!
    strError || strError.length ==0
                  { 
                    
    strError objValue.name " : value should be less than "cmdvalue
                  }
    //if               
                  
    alert(strError); 
                  return 
    false;                 
                 }
    //if             
                
    break; 
             }
    //case lessthan 
            
    case "gt"
            case 
    "greaterthan"
             { 
                if(
    isNaN(objValue.value)) 
                { 
                  
    alert(objValue.name+": Should be a number "); 
                  return 
    false
                }
    //if 
                 
    if(eval(objValue.value) <=  eval(cmdvalue)) 
                 { 
                   if(!
    strError || strError.length ==0
                   { 
                     
    strError objValue.name " : value should be greater than "cmdvalue
                   }
    //if               
                   
    alert(strError); 
                   return 
    false;                 
                 }
    //if             
                
    break; 
             }
    //case greaterthan 
            
    case "regexp"
             { 
                if(!
    objValue.value.match(cmdvalue)) 
                { 
                  if(!
    strError || strError.length ==0
                  { 
                    
    strError objValue.name+": Invalid characters found "
                  }
    //if                                                               
                  
    alert(strError); 
                  return 
    false;                   
                }
    //if 
               
    break; 
             }
    //case regexp 
            
    case "dontselect"
             { 
                if(
    objValue.selectedIndex == null
                { 
                  
    alert("BUG: dontselect command for non-select Item"); 
                  return 
    false
                } 
                if(
    objValue.selectedIndex == eval(cmdvalue)) 
                { 
                 if(!
    strError || strError.length ==0
                  { 
                  
    strError objValue.name+": Please Select one option "
                  }
    //if                                                               
                  
    alert(strError); 
                  return 
    false;                                   
                 } 
                 break; 
             }
    //case dontselect 
             
    case 'codicefiscale':
             {
               var 
    regular = /^[A-Za-z]{6}[0-9]{2}[A-Za-z]{1}[0-9]{2}[A-Za-z]{1}[0-9]{3}[A-Za-z]{1}$/;
               return 
    regular.test(objValue.value);
             }
    //case 'codicefiscale'
        
    }//switch 
        
    return true

    L'ho messo in fondo, è un test su di un espressione regolare che ho trovato qui:

    http://forum.html.it/forum/showthread/t-687949.html

    Ah, ed ovviamente devi crearlo con la descrizione giusta:

    <script language="JavaScript" type="text/javascript">
    var frmvalidator = new Validator("pippo");
    validator.addValidation("nome","codicefiscale","Inserire il proprio nome");
    </script>

  3. #3

    Grazie Mille per la risposta
    No il validatr non l'ho fatto io, è sato fornito da 1 amico e non so quali origini possa avere.

    Domanda
    L'aggiunta che hai fatto tiene conto di nome cognome data di nascita e provincia inseriti precedentemente?
    Tanto...lo fanno tutti... posso farlo anche io vero?

  4. #4
    Frontend samurai L'avatar di fcaldera
    Registrato dal
    Feb 2003
    Messaggi
    12,924
    potresti provare ad usare questa

    http://code.google.com/p/hform/
    http://code.google.com/p/hform/wiki/HowTo

    questa funzionerebbe così
    dopo aver controllato che il CF sia conforme all'espressione regolare fai partire una funzione di callback e in quella funzione fai un controllo tra i dati restanti (data nascita, provincia...) con le varie sottostringhe del codice fiscale.
    Vuoi aiutare la riforestazione responsabile?

    Iscriviti a Ecologi e inizia a rimuovere la tua impronta ecologica (30 alberi extra usando il referral)

  5. #5
    aspetta, io ho solo messo un validatore per il codice fiscale. Non un controllo incrociato. IO direi che a questo punto ti conviene togliere il validatore, inserire readonly al campo codicefiscale, e farlo compilare da JS mano a mano che i dati sono inseriti.

  6. #6
    Originariamente inviato da artorius
    aspetta, io ho solo messo un validatore per il codice fiscale. Non un controllo incrociato. IO direi che a questo punto ti conviene togliere il validatore, inserire readonly al campo codicefiscale, e farlo compilare da JS mano a mano che i dati sono inseriti.

    Bella sta cosa....c'è un tutorial in giro per fare questa cosa molto carina?
    Tanto...lo fanno tutti... posso farlo anche io vero?

  7. #7
    Mi sa di no, devi vedere come il COdice fiscale viene creato, importarti le tabelle e creare la funzione a mano.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.