package Control;
import java.util.regex.*;
public class Validaciones {
public static String mensaje;
public static boolean rut(String rut)
{
boolean tiro = false;
Pattern rut1 = Pattern.compile("^\\d{1,2}+.\\d{3}+.\\d{3}[-][0-9kK]{1}$");
if(!rut1.matcher(rut).find())
mensaje = "El RUT debe tener el siguiente formato: xx.xxx.xxx-x";
else
{
String dv = rut.substring(rut.length()-1, rut.length()).toUpperCase();
rut = rut.substring(0,rut.length()-2);
String rut_limpio = rut.replace(".", "");
int rut_ver = Integer.parseInt(rut_limpio);
int Digito;
int Contador;
int Multiplo;
int Acumulador;
String rutDigito;
Contador = 2;
Acumulador = 0;
while (rut_ver != 0)
{
Multiplo = (rut_ver % 10) * Contador;
Acumulador = Acumulador + Multiplo;
rut_ver = rut_ver/10;
Contador = Contador + 1;
if (Contador == 8)
{
Contador = 2;
}
}
Digito = 11 - (Acumulador % 11);
rutDigito = Integer.toString(Digito);
if (Digito == 10 )
{
rutDigito = "K";
}
else if (Digito == 11)
{
rutDigito = "0";
}
if(rutDigito.equals(dv))
tiro = true;
else
mensaje = "Digito Verificador incorrecto.";
}
return tiro;
}
public static boolean soloLetras(String cadena)
{
if(Pattern.matches("[A-Za-z]+", cadena))
return true;
else
{
mensaje = "Sólo se aceptan letras para el campo ";
return false;
}
}
}
jojojo saludos hermano xD