private static readonly string[] FiCheckChars = new string[] {"0","1","2","3","4","5","6","7","8",
"9","a","b","c","d","e","f","h",
"j","k","l","m","n","p","r",
"s","t","u","v","w","x","y"};
public bool IsCivicRegistrationNumberValid(string civicNumber)
{
if (civicNumber == null)
return false;
var cleanedCivicNumber = civicNumber.Replace("-", "");
if (cleanedCivicNumber.Length != 10)
return false;
if (!IsDateValid(cleanedCivicNumber.Substring(0, 6), "ddMMyy", "fi-FI"))
return false;
// Valid check character?
var vNr = double.Parse(cleanedCivicNumber.Substring(0, cleanedCivicNumber.Length - 1));
var vCheck = (int)(vNr % 31);
var letterCheck = cleanedCivicNumber.ToLower().Substring(cleanedCivicNumber.Length - 1);
return FiCheckChars[vCheck] == letterCheck;
}
Fork
0 Feedback
You must log in before you can give any feedback
You must log in before you can post a comment


570
0




Mark 'c#' tag as 'like'
Mark 'c#' tag as 'ignore'