Delphi 校验方法示例
if custBeforePostCheck(DataSet.FieldByName(‘NAME’).AsString,‘1’) then
begin
MessageDlg(‘中文名称处不能有空格!’, mtInformation, [mbOk], 0);
Abort;
end;
if custBeforePostCheck(DataSet.FieldByName(‘BUSINOTE’).AsString,‘2’) then
begin
MessageDlg(‘税务识别号只能录入数字和字母!’, mtInformation, [mbOk], 0);
Abort;
end;
if custBeforePostCheck(DataSet.FieldByName(‘IDCODE_RMB’).AsString,‘3’) then
begin
MessageDlg(‘RMB银行账号,不允许录入非数字字符!’, mtInformation, [mbOk], 0);
Abort;
end;
if custBeforePostCheck(DataSet.FieldByName(‘IDCODE_USD’).AsString,‘3’) then
begin
MessageDlg(‘USD银行账号,不允许录入非数字字符!’, mtInformation, [mbOk], 0);
Abort;
end;
procedure TCustInfoForm.BUSINOTEEditExit(Sender: TObject);
begin
if custBeforePostCheck(MDBEdit24.text,‘2’) then
begin
MessageDlg(‘税务识别号只能录入数字和字母!’, mtInformation, [mbOk], 0);
Abort;
end;
end;
方法
function TCustInfoForm.custBeforePostCheck(ValueStr:string;typeInteger: string):boolean;
var
i:integer;
begin
ValueStr:=trim(ValueStr); //去除前后空格
if (typeInteger = ‘1’) then
for i:=1 to length(ValueStr) do //循环
begin
if ( ValueStr[i] = ’ ’ ) then //如果空格或回车
begin
result:=true; //是 中断循环
exit;
end
else
begin
result:=false; //不是 继续循环
end;
end;
if (typeInteger = ‘2’) then
for i:=1 to length(ValueStr) do //循环
begin
if ( (ValueStr[i] in [‘0’…‘9’]) or (ValueStr[i] in [‘A’…‘Z’]) or (ValueStr[i] in [‘a’…‘z’])) then //如果字节是数字或字母
begin
result:=false; //是 继续循环
end
else
begin
result:=true; //不是 中断循环
exit;
end;
end;
if (typeInteger = ‘3’) then
for i:=1 to length(ValueStr) do //循环
begin
if ( ValueStr[i] in [‘0’…‘9’]) then //如果字节是数字
begin
result:=false; //是 继续循环
end
else
begin
result:=true; //不是 中断循环
exit;
end;
end;
end;