Last active
August 29, 2015 13:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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