delphi中判断逻辑的写法.

lyn_congcong 2005-03-30 10:21:38
有两个文本框,edit1,edit2.
要求如下:
edit1必须输入内容,且内容必须是11位数字,
edit2可以不输入内容,如果输入内容了也必须是11位数字.
判断逻辑应该怎么写.
...全文
200 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Love_birds 2005-03-30
  • 打赏
  • 举报
回复
我也把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是复制,粘贴,剪切之类的键!具体你自己查!
duanhai 2005-03-30
  • 打赏
  • 举报
回复
我也來一個
要求,需要在OnKeyPress中控件輸入的字符,既然是要求全部為數字,那麼空格肯定不在此范圍了
if (length(edit1.text) <> 11) or
((edit2.text <> '') and (length(edit2.text)<>11)) then
begin
...//你的語句
end;
wzn0521 2005-03-30
  • 打赏
  • 举报
回复
可以在onkeypress事件中控制输入数字

判断长度用length

if 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;
Blakhawk 2005-03-30
  • 打赏
  • 举报
回复
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事件种控制就可以了
chinafly 2005-03-30
  • 打赏
  • 举报
回复
(length(edit1.text)=11)and(edit1.text=[0..9,0..9,0..9,0..9,0..9,0..9,0..9,0..9,0..9,0..9,0..9])
何鲁青 2005-03-30
  • 打赏
  • 举报
回复
在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;
---------------------------------------
离开的时候判断长度...
SeaWave 2005-03-30
  • 打赏
  • 举报
回复
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}”

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧