delphi中限制文本框的输入格式及范围
发布网友
发布时间:2022-05-02 01:22
我来回答
共2个回答
热心网友
时间:2022-06-26 03:42
刚用了两个钟头,实现了这个功能,代码有点长,如下:
procere TForm1.Edit1Change(Sender: TObject);
var
s:string;
str:string;
x:integer;
begin
s:=edit1.Text;
if (pos('A',COPY(s,1,1))=1) then
begin
edit1.Text:=EDIT1.Text;
end
else
begin
s:=edit1.Text;
delete(s,1,1);
edit1.Text:=s;
end;
if (pos('A',copy(edit1.Text,2,2))=1) then
begin
edit1.Text:=EDIT1.Text;
end
else
begin
s:=edit1.Text;
delete(s,2,2);
edit1.Text:=s;
end;
if (pos('0',copy(edit1.Text,3,3))=1) or (pos('1',copy(edit1.Text,3,3))=1) then
begin
edit1.Text:=edit1.Text;
end
else
begin
s:=edit1.Text;
delete(s,3,3);
edit1.Text:=s;
end;
if( (pos('1',copy(edit1.Text,4,4))=1) or (pos('2',copy(edit1.Text,4,4))=1) or (pos('3',copy(edit1.Text,4,4))=1)
or (pos('4',copy(edit1.Text,4,4))=1)or (pos('5',copy(edit1.Text,4,4))=1)or (pos('6',copy(edit1.Text,4,4))=1)
or (pos('7',copy(edit1.Text,4,4))=1)or (pos('8',copy(edit1.Text,4,4))=1)or (pos('9',copy(edit1.Text,4,4))=1)
or (pos('0',copy(edit1.Text,4,4))=1))
then
begin
edit1.text:=edit1.Text;
end
else
begin
s:=edit1.Text;
delete(s,4,4);
edit1.Text:=s;
end;
if (pos('1',copy(edit1.Text,3,3))=1) AND (length(edit1.Text)=4)
then
begin
s:=edit1.Text;
delete(s,4,4);
edit1.Text:=s+'0';
end;
edit1.Text:=copy(edit1.Text,1,4);
end;追问很感谢你们的热心帮助。
热心网友
时间:2022-06-26 03:42
输入是不太好控制,在onchanging事件里加代码吧