Skip to content

Instantly share code, notes, and snippets.

@Vloz
Last active August 29, 2015 13:59
Show Gist options
  • Save Vloz/10505355 to your computer and use it in GitHub Desktop.
Save Vloz/10505355 to your computer and use it in GitHub Desktop.
Methode de validation de code SIRET.Renvoi Faux si la chaine contient des lettres.
static bool validsiret(String siret){
if(siret==null)
return false;
String s = siret.replaceAll(' ','');
if(s.length==0)
return false;
List<int> ln = new List<int>();
for (int i = 0; i < s.length ; i++) {
int n = int.parse(s[i], onError:(_){return 127;});
ln.add(i.isEven ? (n * 2 > 9 ? n * 2 - 9 : n * 2) : n);
}
int sum = ln.reduce((a, b) => a + b);
return sum % 10 == 0 && s.length==14 && sum<127;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment