AccessDecimal.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* ==============================================================================
  2. * 功能描述:浮点数字,正数和负数
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/2/28 14:53:43
  5. * ==============================================================================*/
  6. using System;
  7. using System.Linq;
  8. using System.Runtime.CompilerServices;
  9. using System.Text.RegularExpressions;
  10. namespace WPG.MBIPropType
  11. {
  12. public class AccessDecimal : BaseTextInputControl
  13. {
  14. public override bool InputControl(string fullText)
  15. {
  16. string pattern = @"^-?(([1-9]\d*\.\d+)|(0\.\d+)|([1-9]\d*)|(0))$";
  17. Regex regex = new Regex(pattern);
  18. if (fullText.Length == 1)
  19. {
  20. if (!"-".Equals(fullText) && !regex.IsMatch(fullText))
  21. {
  22. return false;
  23. }
  24. return true;
  25. }
  26. if (regex.IsMatch(fullText))
  27. {
  28. return true;
  29. }
  30. return (((fullText.Count<char>((c)=> c=='.') == 1) && (fullText.IndexOf('.') == (fullText.Length - 1))) && (fullText.IndexOf("-.") < 0));
  31. }
  32. }
  33. }