using System.Text.RegularExpressions;
public static void Main()
var f1 = new ForintSzamlaszam("11111111-22222222-33333333");
Console.WriteLine(f1.Ertek);
var f2 = new ForintSzamlaszam("12010635-01715725-00100003");
Console.WriteLine(f2.Ertek);
public class ForintSzamlaszam
private static readonly Regex Formatum =
new Regex("^(?<elso>\\d{8})(-)?(?<masodik>\\d{8})((-)?(?<harmadik>\\d{8}))?$", RegexOptions.Compiled);
public string Ertek => $"{Elso}-{Masodik}-{Harmadik}";
public string RovidErtek => $"{Elso}{Masodik}{Harmadik}";
private string Elso { get; }
private string Masodik { get; }
private string Harmadik { get; }
public ForintSzamlaszam(string szamlaszam)
if (string.IsNullOrWhiteSpace(szamlaszam))
throw new Exception($"Üres forintszámla!");
var match = Formatum.Match(szamlaszam);
throw new Exception($"Hibás forintszámla formátum! ({szamlaszam})");
var elso = match.Groups["elso"].Value;
var masodik = match.Groups["masodik"].Value;
var harmadik = match.Groups["harmadik"].Success
? match.Groups["harmadik"].Value
if (Ures(elso) || Ures(masodik))
throw new Exception($"Üres forintszámla!");
Console.WriteLine(masodik);
Console.WriteLine(harmadik);
Console.WriteLine(Helyes(elso));
Console.WriteLine(Helyes(masodik));
Console.WriteLine(Helyes(harmadik));
if (!Helyes(elso) || !Helyes(masodik) || !Helyes(harmadik))
throw new Exception($"Hibás forintszámla ellenőrzőösszeg! ({szamlaszam})");
private static bool Ures(string s)
return s.All(c => c == '0');
private bool Helyes(string resz)
return EllenorzoOsszeg(resz) % 10 == 0;
private int EllenorzoOsszeg(string resz)
var s = resz.Select(c => int.Parse(c.ToString())).ToArray();