Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean validarNIF(String nif) {
- boolean correcto = false;
- Pattern pattern = Pattern
- .compile("(\\d{1,8})([TRWAGMYFPDXBNJZSQVHLCKEtrwagmyfpdxbnjzsqvhlcke])");
- Matcher matcher = pattern.matcher(nif);
- if (matcher.matches()) {
- String letra = matcher.group(2);
- String letras = "TRWAGMYFPDXBNJZSQVHLCKE";
- int index = Integer.parseInt(matcher.group(1));
- index = index % 23;
- String reference = letras.substring(index, index + 1);
- correcto =reference.equalsIgnoreCase(letra);
- }
- return correcto;
- }
Advertisement
Add Comment
Please, Sign In to add comment