Advertisement
anibal_bastias

MedioTrabajo

Oct 1st, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1.     public static boolean isEmail(String correo) {
  2.         Pattern pat = null;
  3.         Matcher mat = null;
  4.        
  5.         pat = Pattern.compile("^([0-9a-zA-Z]([+_.-]*[0-9a-zA-Z])*@([a-zA-Z+-]+.){1,2}([a-zA-Z]+))$");
  6.         mat = pat.matcher(correo);
  7.        
  8.         if (mat.find()) {
  9.             System.out.println("[" + mat.group() + "]");
  10.             return true;
  11.         }
  12.         else{
  13.             return false;
  14.         }        
  15.     }
  16.  
  17. public static boolean isChileanRUT(String digit) {
  18.         Pattern pat = null;
  19.         Matcher mat = null;
  20.        
  21.         pat = Pattern.compile("^([0-9]){1,2}.([0-9]){3}.([0-9]){3}-([0-9]){1}$");
  22.         mat = pat.matcher(digit);
  23.        
  24.         if (mat.find()) {
  25.             System.out.println("[" + mat.group() + "]");
  26.             return true;
  27.         }
  28.         else{
  29.             return false;
  30.         }
  31.     }
  32.  
  33.     // Quitar Formato RUT Chileno
  34.     public static String RutNoFormat(String rut)
  35.     {
  36.         while(rut.indexOf(".") != -1)
  37.         {
  38.             rut = rut.replace(".", "");
  39.         }
  40.         while(rut.indexOf("-") != -1)
  41.         {
  42.             rut = rut.replace("-", "");
  43.         }
  44.        
  45.         return rut;
  46.     }
  47.    
  48.     // Setear Formato RUT Chileno
  49.     public static String RutFormat(String rut)
  50.     {
  51.         int cont = 0;
  52.         String format;
  53.         rut = rut.replace(".", "");
  54.         rut = rut.replace("-", "");
  55.         format = "-"+rut.substring(rut.length()-1);
  56.         for(int i = rut.length()-2;i>=0;i--){
  57.             format = rut.substring(i, i+1)+format;
  58.             cont++;
  59.             if(cont == 3 && i != 0){
  60.                 format = "."+format;
  61.                 cont = 0;
  62.             }
  63.         }
  64.         return format;
  65.     }
  66.    
  67.     // Validar RUT Chileno
  68.     public static boolean RutValidate(String rut){
  69.         int dvR,dvT,suma=0;
  70.         int[] serie = {2,3,4,5,6,7};
  71.         rut = rut.replace(".", "");
  72.         rut = rut.replace("-", "");
  73.        
  74.         if(rut.substring(rut.length() - 1).equals("K"))
  75.         {
  76.             dvR = 10;
  77.         }
  78.         else
  79.         {
  80.             dvR = Integer.valueOf(rut.substring(rut.length()-1));
  81.         }
  82.        
  83.         for(int i = rut.length()-2;i>=0; i--){
  84.             suma +=  Integer.valueOf(rut.substring(i, i+1))*serie[(rut.length()-2-i)%6];
  85.         }
  86.        
  87.         dvT=11-suma%11;
  88.        
  89.         if(dvT == dvR){
  90.             return true;
  91.         }else{
  92.             return false;
  93.         }
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement