if Length(Trim(Edit1.Text))<>11 then showmessage('Edit1 Error');if Length(Trim(Edit2.Text))<>0 then if Length(Trim(Edit2.Text))<>11 then showmessage('Edit2 Error'); 关于数字的控制你分别在KeyPress事件种控制就可以了
可以在onkeypress事件中控制输入数字判断长度用lengthif length(trim(edit1.text)) <> 11 then begin showmessage('error'); exit; end; if length(trim(edit2.text)) <> 0 and length(trim(edit2.text)) <> 11 then begin showmessage('error'); exit; end;
我也來一個 要求,需要在OnKeyPress中控件輸入的字符,既然是要求全部為數字,那麼空格肯定不在此范圍了 if (length(edit1.text) <> 11) or ((edit2.text <> '') and (length(edit2.text)<>11)) then begin ...//你的語句 end;
我也把keypressg事件给你: procedure TFWYDLB01.Lbl_LineKeyPress(Sender: TObject; var Key: Char); begin if (not(key in ['0'..'9',#8,#13,#3,#22,#24])) then begin key := #0 ; exit; end; end; 看看吧: #3,#22,#24是复制,粘贴,剪切之类的键!具体你自己查!
var s: String; i: Integer; begin s := Edit1.Text; i := Length(s); if i<>11 then 错误; while i>0 do if not (s[i] in ['0'..'9']) then 错误; s := Edit2.Text; i := Length(s); if i=0 then Exit; if i<>11 then 错误; while i>0 do if not (s[i] in ['0'..'9']) then 错误; end ---------------- 还有一个办法是用正则表达式,搜索匹配是否存在,匹配串为“\d{11}”
在keypress里面判断输入的是数字 -------------------------- procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if not(Key in ['0'..'9',#8,#13,#3,#22,#24]) then Key:=#0; end;procedure TForm1.Edit1Exit(Sender: TObject); begin if length(edit1.Text)<>11 then begin showmessage('长度不符合条件'); edit1.SetFocus; end; end; --------------------------------------- 离开的时候判断长度...
then showmessage('Edit1 Error');if Length(Trim(Edit2.Text))<>0
then if Length(Trim(Edit2.Text))<>11
then showmessage('Edit2 Error');
关于数字的控制你分别在KeyPress事件种控制就可以了
begin
showmessage('error');
exit;
end;
if length(trim(edit2.text)) <> 0 and length(trim(edit2.text)) <> 11 then
begin
showmessage('error');
exit;
end;
要求,需要在OnKeyPress中控件輸入的字符,既然是要求全部為數字,那麼空格肯定不在此范圍了
if (length(edit1.text) <> 11) or
((edit2.text <> '') and (length(edit2.text)<>11)) then
begin
...//你的語句
end;
procedure TFWYDLB01.Lbl_LineKeyPress(Sender: TObject; var Key: Char);
begin
if (not(key in ['0'..'9',#8,#13,#3,#22,#24])) then begin
key := #0 ;
exit;
end;
end;
看看吧:
#3,#22,#24是复制,粘贴,剪切之类的键!具体你自己查!
s: String;
i: Integer;
begin
s := Edit1.Text;
i := Length(s);
if i<>11 then 错误;
while i>0 do
if not (s[i] in ['0'..'9']) then 错误;
s := Edit2.Text;
i := Length(s);
if i=0 then Exit;
if i<>11 then 错误;
while i>0 do
if not (s[i] in ['0'..'9']) then 错误;
end
----------------
还有一个办法是用正则表达式,搜索匹配是否存在,匹配串为“\d{11}”
--------------------------
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not(Key in ['0'..'9',#8,#13,#3,#22,#24]) then
Key:=#0;
end;procedure TForm1.Edit1Exit(Sender: TObject);
begin
if length(edit1.Text)<>11 then
begin
showmessage('长度不符合条件');
edit1.SetFocus;
end;
end;
---------------------------------------
离开的时候判断长度...