用maskedit或者在keypress里写代码

解决方案 »

  1.   

    这是你说的第一中procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if (not (key  in['0','1','2','3','4','5','6','7','8','9']) ) or (length(edit1.Text) >6) then
        MessageBeep(1);
        key:=#0 ;
    end;
      

  2.   

    应该在OnChange做要好一点,作出一个判断!
      

  3.   

    在edit的onKeyPress里写
    1:(Edit1)
      if Not (Key in ['0'..'9',#13,#8,#46]) then
      Key := #0;
      另外在 FormCreate里写
      Edit1.MaxLength := 6;
    2:(Edit2)
      if Not (Key in ['a'..'z','A'..'Z',#13,#8,#46]) then
      Key := #0;
      另外在FormCreate里写;
      Edit2.MszLength := 20;
      

  4.   

    写在KeyPress中
    if (key<#47) or (Key>#57) then
      Key := #0;
    关于长度设置Edit的MaxLength=6即可
    还有一点,你还得加上退格键