if key in ['0'..'9',#13,#8 ] then
  ....
else
  key:=#0;
在keypress中写

解决方案 »

  1.   

    onPress
    if Key in ['a'..'z','A'..'Z'] then
    Key := #0;
      

  2.   

    在keypress中增加:  if not ((key >= '0') and (key <= '9')) then
        if ((key <> '.') and (key <> #8)) or
          ((key = '.') and (pos('.', Trim(Edit1.text)) > 0)) then
          key := #0;
      

  3.   

    上边是不允许有字母的,嘻嘻,但是 '.','/'...还是可以的;//你的要求嘛;
    if Not (key in ['0'..'9',#13,#8,#46 ]) then
      begin
        Key := #0;
        Exit;
      end;
    //这儿是只许字的,嘻嘻;
      

  4.   

    在 KeyDown 或 KeyPress 事件中判断其 Key 值, 
    如果为字母则提示或直接取消本次按键
      

  5.   

    我想,你是想让用户只输入数字,可以这样:
    在OnKeyPress 中
       
      if not (Key in ['0'..'9']) and (word(Key) <> vk_back) then
         Key := #0;这样也可以使用户的BackSpace键和Delete键好使,最后加个空的PopupMenu给这个编辑框,禁止粘贴进非法字符