50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace IBANNummerPrüfen
|
|
{
|
|
public class IbanPrüfung
|
|
{
|
|
// Richtiges IBAN Format: DE68 2105 0170 0012 3456 78
|
|
//private string? IBAN;
|
|
private string? ibanCleared;
|
|
private string? ibanSwapped;
|
|
private string? sum;
|
|
private string? iban;
|
|
public void SetIbanPrüfungEntgegennehmen()
|
|
{
|
|
Console.Write("Bitte geben Sie ihre IBAN-Nummer ein: ");
|
|
this.iban = Console.ReadLine();
|
|
|
|
Console.WriteLine(IBANPrüfung());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bestimmt ob die Checksumme einer IBAN gültig ist
|
|
/// </summary>
|
|
/// <param name="iban">Der zu prüfende IBAN (z.B: "DE68 2105 0170 0012 3456 78")</param>
|
|
/// <returns><c>True</c>, wenn <paramref name="value"/> gültig ist. Andernfalls <c>False</c>.</returns>
|
|
public bool IBANPrüfung()
|
|
{
|
|
if (this.iban != null)
|
|
{
|
|
this.ibanCleared = this.iban.ToUpper().Replace(" ", "").Replace("-", "").Replace(".", "");
|
|
//Console.WriteLine(ibanCleared);
|
|
this.ibanSwapped = ibanCleared.Substring(4) + ibanCleared.Substring(0, 4);
|
|
//Console.WriteLine(ibanSwapped);
|
|
this.sum = ibanSwapped.Aggregate("", (current, c) => current + (char.IsLetter(c) ? (c - 55).ToString() : c.ToString()));
|
|
//Console.WriteLine(sum);
|
|
//this.sum = ibanCleared.Aggregate("", (current, c) => current + (char.IsLetter(c) ? (c - 55).ToString() : c.ToString()));
|
|
|
|
var d = decimal.Parse(sum);
|
|
return ((d % 97) == 1);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|