How to make a code generator with homoclave?

  1. DiggClick


How to make a code generator with homoclave?

This example is based on the Curp site 
The example of code that will give you on this occasion will be to calculate the CURP and homoclave RFC with a javascript function, these two documents are highly used in Mexico, they are a requirement for many procedures.
The CURP is the Unique Key Population Registration (CURP) is a unique alphanumeric identification code of 18 characters used to officially identify both residents and Mexican citizens across the country.
and RFC with homoclave is a key that requires any natural or legal person in Mexico to perform any lawful economic activity for which he is liable to pay any corporation tax, with some exceptions.
For this I made a javascript function that can launch any event, a onclick, an onchange, etc., if they have served, cleared … not the numeric digits as are calculated, so that while they are only of the linkages letters, if anyone knows they are based for these antics in the end, porfas complement the note to have the complete function.

function calculaRFCURP() {
var paterno1st = document.getElementById(‘txt_paterno’).value;


paterno1st = paterno1st.replace(“LAS”,””);
paterno1st = paterno1st.replace(“DEL”,””);

var paterno  = paterno1st.replace(“LA”,””);
paterno = paterno.replace(“DE”,””);
paterno = paterno.replace(“Y”,””);

while(paterno[0] == ” “){
paterno = paterno.substr(1, paterno.length – 1);

var materno1st = document.getElementById(‘txt_materno’).value;
var materno1st = materno1st.replace(“LAS”,””);
materno1st = materno1st.replace(“DEL”,””);
materno1st = materno1st.replace(“DE”,””);

var materno  = materno1st.replace(“LA”,””);
materno = materno.replace(“Y”,””);

while(materno[0] == ” “){
materno = materno.substr(1, materno.length – 1);

var nombre = document.getElementById(‘txt_nombre’).value.toUpperCase();
var op_paterno = paterno.length;
var vocales = /^[aeiou]/i;
var consonantes = /^[bcdfghjklmnñpqrstvwxyz]/i;

var s1 = ”;
var s2 = ”;
var s8 = ”;

var i = 0;
var x= true;
var z = true;

while(i < op_paterno){
if((consonantes.test(paterno[i]) == true) & (x != false)){
s1 = s1 + paterno[i];
paterno = paterno.replace(paterno[i],””);

if((vocales.test(paterno[i]) == true) & (z != false)){
s2 = s2 + paterno[i];
paterno = paterno.replace(paterno[i],””);

var ix=0;
var y = true;
var nparteno = paterno.length;

while(ix < nparteno){
if((consonantes.test(paterno[ix]) == true) & (y != false)){
s8 = s8 + paterno[ix];

//calculos apellido materno
var maternosize = materno.length;
var j = 1;
var s9 = ”;
var xm = true;
var ym = true;

while(j < maternosize){
if((consonantes.test(materno[j]) == true) && (xm != false)){
s9 = s9.replace(materno[j],””);
xm = false;

if((consonantes.test(materno[j]) == true) && (ym != false)){
s9 = s9 + materno[j];
ym = false;


var nombresize = nombre.length;
var im = 1;
var s10= ”;
var wx = true;
var wz = true;

while(im < nombresize){

if((consonantes.test(nombre[im]) == true)&& (wz != false)){
s10 = s10 + nombre[im];
nombre = nombre.replace(nombre[im],””);
wz = false;

var sexo = document.getElementById(“select_sexo”).value;
if( sexo == ‘HOMBRE’){ sexo = ‘H’;}else{ sexo =’M’;}
var edo = document.getElementById(“select_estado”).options[document.getElementById(“txt_estado”).selectedIndex].text.toUpperCase();

case “AGUASCALIENTES”: edo=”AS”; break;
case “BAJA CALIFORNIA”:edo=”BC”; break;
case “BAJA CALIFORNIA SUR”: edo=”BS”; break;
case “CAMPECHE”: edo=”CC”; break;
case “COAHUILA DE ZARAGOZA”: edo=”CL”; break;
case “COLIMA”: edo=”CM”; break;
case “CHIAPAS”: edo=”CS”; break;
case “CHIHUAHUA”: edo=”CH”; break;
case “DISTRITO FEDERAL”: edo=”DF”; break;
case “DURANGO”: edo=”DG”; break;
case “GUANAJUATO”: edo=”GT”; break;
case “GUERRERO”: edo=”GR”; break;
case “HIDALGO”: edo=”HG”; break;
case “JALISCO”: edo=”JC”; break;
case “MÉXICO”: edo=”MC”; break;
case “MICHOACÁN DE OCAMPO”: edo=”MN”; break;
case “MORELOS”: edo=”MS”; break;
case “NAYARIT”: edo=”NT”; break;
case “NUEVO LEÓN”: edo=”NL”; break;
case “OAXACA”: edo=”OC”; break;
case “PUEBLA”: edo=”PL”; break;
case “QUERÉTARO”: edo=”QT”; break;
case “QUINTANA ROO”: edo=”QR”; break;
case “SAN LUIS POTOSÍ”: edo=”SP”; break;
case “SINALOA”: edo=”SL”; break;
case “SONORA”: edo=”SR”; break;
case “TABASCO”: edo=”TC”; break;
case “TAMAULIPAS”: edo=”TS”; break;
case “TLAXCALA”: edo=”TL”; break;
case “VERACRUZ DE IGNACIO DE LA LLAVE”: edo=”VZ”; break;
case “YUCATÁN”: edo=”YN”; break;
case “ZACATECAS”: edo=”ZS”; break;

var s3 = materno[0];
var s4 = nombre[0];

var fecha = document.getElementById(“txt_fecha”).value;
var fechaSplit = fecha.split(“/”);

var s5 = fechaSplit[2][2]+fechaSplit[2][3];
var s6 = fechaSplit[1];
var s7 = fechaSplit[0];

document.getElementById(‘txt_RFC’).value = s1+s2+s3+s4+s5+s6+s7;
document.getElementById(‘txt_CURP’).value = s1+s2+s3+s4+s5+s6+s7+sexo+edo+s8+s9+s10;


Well I hope will be useful and this contribution, any doubt I am to listen, Greetings!