TxtIDCard.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace Dongke.WinForm.Controls
  6. {
  7. /// <summary>
  8. /// 身份证输入文本框
  9. /// </summary>
  10. [ToolboxBitmap(typeof(TextBox))]
  11. public class TxtIDCard : TextBoxCodeBase
  12. {
  13. #region 构造函数
  14. /// <summary>
  15. /// 身份证输入文本框
  16. /// </summary>
  17. public TxtIDCard()
  18. {
  19. this.Rejected = "[^0-9xX]";
  20. this.Regular = @"^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$";
  21. base.MaxLength = 18;
  22. base.MinLength = 15;
  23. }
  24. #endregion
  25. #region 重写属性
  26. /// <summary>
  27. /// 获取或设置用户可在文本框控件中键入或粘贴的最大字符数。
  28. /// </summary>
  29. [Browsable(false)]
  30. [EditorBrowsable(EditorBrowsableState.Never)]
  31. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  32. public override int MaxLength
  33. {
  34. get
  35. {
  36. return base.MaxLength;
  37. }
  38. set
  39. {
  40. base.MaxLength = value;
  41. }
  42. }
  43. /// <summary>
  44. /// 获取或设置允许输入的最小长度。
  45. /// </summary>
  46. [Browsable(false)]
  47. [EditorBrowsable(EditorBrowsableState.Never)]
  48. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  49. public override int MinLength
  50. {
  51. get
  52. {
  53. return base.MinLength;
  54. }
  55. set
  56. {
  57. base.MinLength = value;
  58. }
  59. }
  60. #endregion
  61. }
  62. }