Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2011
    Messaggi
    229

    Algoritmo codice fiscale inverso

    Ciao a tutti,

    devo trovare data e sesso di un "utente" dal suo codice fiscale. Esiste qualcosa in JavaScript per far questo?

    Grazie

  2. #2
    Frontend samurai L'avatar di fcaldera
    Registrato dal
    Feb 2003
    Messaggi
    12,924
    Cosa hai provato a fare finora?

    i dati sul sesso e data di nascita sono contenuti nella sottostringa (6,10) : xxxxxx00x00x000x

    quindi data una stringa cf contenente il codice fiscale

    1) ricavi la sottostringa 6,10 ottenendo una stringa lunga 5 (00x00)

    2) le prime due cifre sono l'anno di nascita. ma considera che se l'anno è compreso tra 0 e 12 l'anno potrebbe essere tanto 1900 quanto 2000

    3) il terzo carattere rappresenta il mese secondo lo schema spiegato qui: http://it.wikipedia.org/wiki/Codice_fiscale

    4) le ultime due cifre sono il giorno di nascita: se è maggiore di 40 significa che si tratta di una persona di sesso femminile (e devi sottrarre quindi 40 per ottenere il giorno di nascita), maschile altrimenti.
    Vuoi aiutare la riforestazione responsabile?

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

  3. #3
    Utente di HTML.it
    Registrato dal
    Dec 2011
    Messaggi
    229
    Ciao!Si ho visto che per i dati che mi servono, devo prendere in considerazione le 5 cifre centrali del codice.

    E' la prima volta che uso le funzioni ma sto usando vb non javascript, sono fuori sezione alla grande. Come posso spostare?

    Ho fatto il form per passare alla funzione il cod_fisc
    codice:
    <form name="dati" method="post" action="defalut.asp">
        <input type="text" name="cod" />
        <input type="submit" value="Estrapola" name="Estrapola"/>
    </form>
    la funzione, in testa alla pagina, è la seguente
    codice:
    <%
    dim a
    if request.form("Estrapola") <> "" then
    	function Estrapola(cod_fisc)
    		cod_fisc=request.Form("cod")
    		a=(mid(cod_fisc,7,5))
    	
    	end function 
    end if
    %>
    per poi provare a stampare l'elaborazione della funzione (che non stampa una mazza)
    codice:
    <%
        response.Write(Estrapola(cod_fisc))
    %>

    Come mai non stampa?E' giusto il mid in funzione?


  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,563
    Dentro la funzione.

    Estrapola = a

    Roby

  5. #5
    Utente di HTML.it
    Registrato dal
    Dec 2011
    Messaggi
    229
    la funzione quanti valori può "uscire"?

    Ho calcolato giorno, mese, anno e sesso, in 4 variabili diverse ovviamente.

    Come faccio a estrapolare le 4 variabili?

    ho provato
    Estrapola=giorno
    Estrapola=mese
    Estrapola=anno
    Estrapola=sesso

    ma mi non va, legge solo un valore.

    grazie Roby

  6. #6
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,563
    metti un separatore...

  7. #7
    Utente di HTML.it
    Registrato dal
    Dec 2011
    Messaggi
    229
    Separatore?

    Retifico la funzione va, mi restituisce i valori apparte il giorno (e il sesso che sono concatenati).

    Praticamente faccio:
    codice:
    		gior=(mid(cod_fisc,10,2))
    		g=cint(gior)
    e mi da errore tipo non corrispondente..ma dovrebbero essere corrette le cifre riportate...a sapere come vederle...

  8. #8
    Utente di HTML.it
    Registrato dal
    Dec 2011
    Messaggi
    229
    codice:
    <%
    dim a, anno, m, mese, g, giorno, sesso, gior
    if request.form("Estrapola") <> "" then
    	function Estrapola(cod_fisc)
    		cod_fisc=request.Form("cod")
    		a=(mid(cod_fisc,7,2))
    		anno=cstr("19"+a)
    		m=(mid(cod_fisc,9,1))
    		if m="A" then
    			mese="Gennaio"
    		end if
    		if m="B" then
    			mese="Febbraio"
    		end if
    		if m="C" then
    			mese="Marzo"
    		end if
    		if m="D" then
    			mese="Aprile"
    		end if
    		if m="E" then
    			mese="Maggio"
    		end if
    		if m="F" then
    			mese="Giugno"
    		end if
    		if m="G" then
    			mese="Luglio"
    		end if
    		if m="H" then
    			mese="Agosto"
    		end if
    		if m="I" then
    			mese="Settembre"
    		end if
    		if m="L" then
    			mese="Ottobre"
    		end if
    		if m="M" then
    			mese="Novembre"
    		end if
    		if m="N" then
    			mese="Dicembre"
    		end if
    		
    		gior=(mid(cod_fisc,10,2))
    		g=cint(gior)
    		
    		if g>40 then
    			sesso="F"		
    			g=cstr(g-40)
    			if len(g)=1 then
    				giorno="0"+g
    			else
    				giorno=g
    			end if
    		else
    			sesso="M"
    			if len(g)=1 then
    				giorno="0"+g
    			else
    				giorno=g
    			end if
    		end if
    		Estrapola=giorno
    		Estrapola=sesso
    		Estrapola=anno	
    		Estrapola=mese
    		end function 
    end if
    
    %>
    questo è il codice, stampa solo MarzoMarzo...

  9. #9
    Utente di HTML.it
    Registrato dal
    Dec 2011
    Messaggi
    229
    risotto
    codice:
    <%
    dim a, anno, m, mese, g, giorno, sesso, gior
    if request.form("Estrapola") <> "" then
    	function Estrapola(cod_fisc)
    		cod_fisc=UCASE(request.Form("cod"))
    		a=(mid(cod_fisc,7,2))
    		anno=cstr("19"&a)
    		m=(mid(cod_fisc,9,1))
    		if m="A" then
    			mese="01"
    		end if
    		if m="B" then
    			mese="02"
    		end if
    		if m="C" then
    			mese="03"
    		end if
    		if m="D" then
    			mese="04"
    		end if
    		if m="E" then
    			mese="05"
    		end if
    		if m="H" then
    			mese="06"
    		end if
    		if m="L" then
    			mese="07"
    		end if
    		if m="M" then
    			mese="08"
    		end if
    		if m="P" then
    			mese="09"
    		end if
    		if m="R" then
    			mese="10"
    		end if
    		if m="S" then
    			mese="11"
    		end if
    		if m="T" then
    			mese="12"
    		end if
    		
    		gior=(mid(cod_fisc,10,2))
    		g=cint(gior)
    		
    		if g>40 then
    			sesso="F"		
    			g=cstr(g-40)
    			if len(g)=1 then
    				giorno="0" & g
    			else
    				giorno=g
    			end if
    		else
    			sesso="M"
    			if len(g)=1 then
    				giorno="0" & g
    			else
    				giorno=g
    			end if
    		end if
    		Estrapola=giorno & "/" & mese & "/" & anno & "-" & sesso
    		end function 
    end if
    
    %>
    shere it!!!

  10. #10
    Originariamente inviato da Gio2011
    risotto

    Mi hai fatto venir fame!!

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.