AHi esta en javascript
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) == true) & (x != false)){
s1 = s1 + paterno;
paterno = paterno.replace(paterno,"");
x=false;
}
if((vocales.test(paterno) == true) & (z != false)){
s2 = s2 + paterno;
paterno = paterno.replace(paterno,"");
z=false;
}
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];
y=false;
}
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;
}
j++;
}
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;
}
im++;
}
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();
switch(edo){
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;
}
Aqui esta la otra funcion en js de gobernación:
/* ******************************************************************************************* */
// Esta ya no es necesaria, despues de las pruebas se puede borrar 23-6-2003
function validaCURP2(curp){
var segRaiz = "";
var digVer = "";
var lngSuma = 0.0;
var lngDigito = 0.0;
var strDigitoVer = "";
var intFactor = new Array(17);
var chrCaracter = "0123456789ABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
segRaiz = curp.substring(0,17);
digVer = curp.substring(17,18);
for(var i=0; i<17; i++)
{
for(var j=0;j<37; j++)
{
if(segRaiz.substring(i,i+1)==chrCaracter.substring(j,j+1))
{
intFactor=j;
}
}
}
for(var k = 0; k < 17; k++)
{
lngSuma= lngSuma + ((intFactor[k]) * (18 - k));
}
lngDigito= (10 - (lngSuma % 10));
if(lngDigito==10)
{
lngDigito=0;
}
var reg = /[A-Z]{4}\d{6}[HM][A-Z]{2}[B-DF-HJ-NP-TV-Z]{3}[A-Z0-9][0-9]/;
if(curp.search(reg))
{
alert("La curp: " + curp + " no es valida, verifiqué ");
return false;
}
if(!(parseInt(lngDigito)==parseInt(digVer)))
{
alert("La curp: " + curp + " no es valida, revisé el Digito Verificador (" + lngDigito + ")");
return false;
}
return true;
}
/* ******************************************************************************************* */
function validaCURP(curp){
var reg = "";
if(curp.length == 18)
{
var digito = calculaDigito(curp);
reg = /[A-Z]{4}\d{6}[HM][A-Z]{2}[B-DF-HJ-NP-TV-Z]{3}[A-Z0-9][0-9]/;
if(curp.search(reg))
{
alert("La curp: " + curp + " no es valida, verifiqué ");
return false;
}
if(!(parseInt(digito) == parseInt(curp.substring(17,18))))
{
alert("La curp: " + curp + " no es valida, revisé el Digito Verificador (" + digito + ")");
return false;
}
return true;
}
else
{
switch (curp.length)
{
case 10 :
reg = /[A-Z]{4}\d{6}/;
break;
case 11 :
reg = /[A-Z]{4}\d{6}[HM]/;
break;
case 12 :
reg = /[A-Z]{4}\d{6}[HM][A-Z]/;
break;
case 13 :
reg = /[A-Z]{4}\d{6}[HM][A-Z]{2}/;
break;
case 14 :
reg = /[A-Z]{4}\d{6}[HM][A-Z]{2}[B-DF-HJ-NP-TV-Z]/;
break;
case 15 :
reg = /[A-Z]{4}\d{6}[HM][A-Z]{2}[B-DF-HJ-NP-TV-Z]{2}/;
break;
case 16 :
reg = /[A-Z]{4}\d{6}[HM][A-Z]{2}[B-DF-HJ-NP-TV-Z]{3}/;
break;
case 17 :
reg = /[A-Z]{4}\d{6}[HM][A-Z]{2}[B-DF-HJ-NP-TV-Z]{3}[A-Z0-9]/;
break;
}
if(curp.search(reg))
{
alert("La curp: " + curp + " no es valida, verifiqué ");
return false;
}
return true;
}
}
/* ******************************************************************************************* */
function calculaDigito(curp){
var segRaiz = curp.substring(0,17);
var chrCaracter = "0123456789ABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
var intFactor = new Array(17);
var lngSuma = 0.0;
var lngDigito = 0.0;
for(var i=0; i<17; i++)
{
for(var j=0;j<37; j++)
{
if(segRaiz.substring(i,i+1)==chrCaracter.substring(j,j+1))
{
intFactor=j;
}
}
}
for(var k = 0; k < 17; k++)
{
lngSuma= lngSuma + ((intFactor[k]) * (18 - k));
}
lngDigito= (10 - (lngSuma % 10));
if(lngDigito==10)
{
lngDigito=0;
}
return lngDigito;
}
/* ******************************************************************************************* */