28 lines
877 B
C#
28 lines
877 B
C#
|
|
using System.Globalization;
|
|||
|
|
using System.Windows.Controls;
|
|||
|
|
|
|||
|
|
namespace ValidationLibrary
|
|||
|
|
{
|
|||
|
|
public class DecimalValidator : ValidationRule
|
|||
|
|
{
|
|||
|
|
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
|||
|
|
{
|
|||
|
|
if (value == null || string.IsNullOrEmpty(value as string))
|
|||
|
|
{
|
|||
|
|
return new ValidationResult(true, null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (value is string)
|
|||
|
|
{
|
|||
|
|
decimal lDecimal;
|
|||
|
|
bool lBool = decimal.TryParse((string)value, NumberStyles.Any, cultureInfo.NumberFormat, out lDecimal);
|
|||
|
|
if (lBool)
|
|||
|
|
{
|
|||
|
|
return new ValidationResult(true, null);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return new ValidationResult(false, "Bitte geben Sie eine g<>ltige Zahl ein");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|