NumValidation.cs 746 B

12345678910111213141516171819202122232425262728
  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,
  21. string.Format("Illegal characters or {0}", e.Message));
  22. }
  23. return new ValidationResult(true, null);
  24. }
  25. }
  26. }