Delphi 中文姓名 合法性检查


本文整理自网络,侵删。

 
function checkCName(value: string): boolean;
var
  i, k: integer;
  cstr, estr: string;
begin
  result := false;
  k := pos(' ', value);

  if k > 0 then // 有空格
  begin
    cstr := copy(value, 1, k-1);
    estr := copy(value, k+1, 255);

    // 汉字部分不全是汉字
    if 2*length(widestring(cstr)) <> length(ansistring(cstr)) then
      exit;

    for i := 1 to length(estr) do // 英文部分不全是英文
    begin
      if not (estr[i] in ['a'..'z', 'A'..'Z']) then
        exit;
    end;
  end else // 没有空格
  begin
    if (2*length(widestring(value)) <> length(ansistring(value))) // 不全是汉字
      and (length(widestring(value)) <> length(ansistring(value))) then // 不全是英文
    begin
      exit;
    end;
  end;

  result := true;
end;

相关阅读 >>

Delphi 文件占坑法过360查杀

Delphi 获取北京时间

Delphi 禁止用户关闭操作系统

Delphi百度网盘真实地址解析

Delphi 回车 选择下一个控件

Delphi下用cdo发送邮箱实例(授权码cdo发送邮箱的解决办法)

Delphi 基础计算两数之合

Delphi显示gif动画简单方法

Delphi什么是thttpclient?

Delphi tadodataset 加载数据到fdmemtable1

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...