红鱼儿

在Delphi中使用正则表达式校验中文姓名

uses
system.RegularExpressions;

function IsChineseName(const aName:string; const aMaxLength:Integer=10):Boolean;
begin
//只检查基本汉字: // var Pattern := '^[\x{4E00}-\x{9FA5}]{2,'+aMaxLength.ToString+'}(·[\x{4E00}-\x{9FA5}]{2,'+aMaxLength.ToString+'}){0,2}$'; //检查下面所有内容: //基本汉字 4E00-9FA5 //基本汉字补充 9FA6-9FCB //扩展A 3400-4DB5 //扩展B 20000-2A6D6 //扩展C 2A700-2B734 //扩展D 2B740-2B81D //兼容汉字 F900-FAD9 var Pattern := '^[\x{4E00}-\x{9FA5}\x{9FA6}-\x{9FCB}\x{3400}-\x{4DB5}\x{20000}-\x{2A6D6}\x{2A700}-\x{2B734}\x{2B740}-\x{2B81D}\x{F900}-\x{FAD9}]{2,'+aMaxLength.ToString +'}(·[\x{4E00}-\x{9FA5}\x{9FA6}-\x{9FCB}\x{3400}-\x{4DB5}\x{20000}-\x{2A6D6}\x{2A700}-\x{2B734}\x{2B740}-\x{2B81D}\x{F900}-\x{FAD9}]{2,'+aMaxLength.ToString+'}){0,2}$'; result:= TRegEx.Match(aName,Pattern).Success; end;

 

直接上代码了!

默认允许10个字的姓名,支持中间有分隔符“·”的姓名。

参数aMaxLength可以设置允许姓名的最大长度。

要引用system.RegularExpressions单元。

参考:

https://www.cnblogs.com/straybirds/p/6392306.html 

https://www.cnblogs.com/kinglandsoft/p/15495209.html

https://www.cnblogs.com/kinglandsoft/p/15654537.html

Unicode 15 版本里的中文字符集范围

 

posted on 2023-10-23 15:37  红鱼儿  阅读(376)  评论(0编辑  收藏  举报