各位大哥又是我,这次的问题很简单!!(50分)

N

nicet

Unregistered / Unconfirmed
GUEST, unregistred user!
我正在写一个用户登陆的界面比如:工号:xxx,密码xxx
现在要求是要做到用户输入的工号必须是'0'-'9'的10个数字,不能是'd'等字母,也
不可以是"#"或其他的字符。每当用户输入错误的字母或字符后,系统提示“工号”应为
'0'-'9'的数字,请重新输入。
怎么写?
 
用maskedit
 
edit 中只输入数字其他的都输不进去
SetWindowLong(Edit1.Handle, GWL_STYLE,
GetWindowLong(Edit1.Handle, GWL_STYLE) or
ES_NUMBER);
 
数字用keypress事件判断就行咯
 
可以在EDIT框的onchange事件中写代码判断输入的字符是否数字
如果不是数字则showmessage。
 
在keypress事件中加入
if not key in['0'..'9', #8, #13] then

begin
key := #0;
ShowMessage('');
end
 
edit1.onkeypress
if key<#30 or key>#40 then
key:=#0
(请查一下0和9的ACSII是否为#30 ,#40
 
your onkeypress events should like this
if not (key in['0'..'9',#8]) then
//#8 backup key
begin
key := #0;
// clear input
your notice message...
end;
 
在输入工号的EDIT控件的KeyPress事件中写入如下代码:
if not ( key in ['0'..'9',#8]) then
key:=#0;即可,不需要输的字符根本数不进去
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
顶部