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

发布时间 2023-10-23 15:41:59作者: 红鱼儿

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}$'; 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