NumValidation.cs 544 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using System.Globalization;
  3. using System.Windows.Controls;
  4. namespace Robot
  5. {
  6. public class NumValidation : ValidationRule
  7. {
  8. public override ValidationResult Validate(object value, CultureInfo cultureInfo)
  9. {
  10. if ((string) value == "")
  11. {
  12. return new ValidationResult(true, null);
  13. }
  14. try
  15. {
  16. int.Parse((string) value);
  17. }
  18. catch (Exception e)
  19. {
  20. return new ValidationResult(false, string.Format("Illegal characters or {0}", e.Message));
  21. }
  22. return new ValidationResult(true, null);
  23. }
  24. }
  25. }