Sprache: C#
Diese Methode validiert eine deutsche Postleitzahl.
/// <summary>
/// Determines whether the specified input is a german zipcode
/// </summary>
/// <param name="canditate">The canditate.</param>
/// <returns>
/// <c>true</c> if [is german zipcode] [the specified canditate]; otherwise, <c>false</c>.
/// </returns>
static bool IsGermanZipcode(string canditate)
{
System.Text.RegularExpressions.Regex pattern = new System.Text.RegularExpressions.Regex(@"^d{5}$");
return pattern.IsMatch(canditate.Trim());
}
/// <summary>
/// Determines whether the specified input is a german zipcode
/// </summary>
/// <param name="canditate">The canditate.</param>
/// <returns>
/// <c>true</c> if [is german zipcode] [the specified canditate]; otherwise, <c>false</c>.
/// </returns>
static bool IsGermanZipcode(string canditate)
{
System.Text.RegularExpressions.Regex pattern = new System.Text.RegularExpressions.Regex(@"^d{5}$");
return pattern.IsMatch(canditate.Trim());
}
Alte URL:
/snippet/deutsche-postleitzahl-validieren/588
So gesehen nicht schlech. Wäre möglich diesen aber noch zu verfeinern. Zum Beispiel gibt es, meines wissens nach als schweizer, keine PLZ mit einer führenden null. Aber das wäre nur eine kleine Verbesserung
Wirklich?. Es wird auf eine 5-stellige Zahl validiert, mehr nicht! Die Postleitzahl 00000 gibt es nicht, was gibt die Funktion zurück? – True. Sehr hilfreich – nein falsch.