Skip to content

Instantly share code, notes, and snippets.

View gplgps's full-sized avatar

Gonçalo Silva gplgps

  • Ovar, Portugal
View GitHub Profile

Keybase proof

I hereby claim:

  • I am gplgps on github.
  • I am gplgps (https://keybase.io/gplgps) on keybase.
  • I have a public key ASC91-NFScJs9Nqlet3DVT8QwdG3TdHYRjWBKA0ZYIpGNQo

To claim this, I am signing this object:

@gplgps
gplgps / CCcheck.java
Last active December 15, 2020 15:05
Portuguese Citizen Card number check for Java
public static boolean validateNumeroDocumentoCC(String numeroDocumento){
// C# Source: https://www.autenticacao.gov.pt/documents/20126/115760/Valida%C3%A7%C3%A3o+de+N%C3%BAmero+de+Documento+do+Cart%C3%A3o+de+Cidad%C3%A3o.pdf
int sum = 0;
boolean secondDigit = false;
if (numeroDocumento == null)
throw new IllegalArgumentException("Número de documento não pode ser null.");
if(numeroDocumento.length() != 12)
throw new IllegalArgumentException("Tamanho inválido para número de documento.");
for (int i = numeroDocumento.length()-1; i >= 0; --i){
int valor = getNumberFromChar(numeroDocumento.charAt(i));