|
@@ -36,10 +36,20 @@ function FormatSeconds(const AValue: Integer): string; overload;
|
|
/// </summary>
|
|
/// </summary>
|
|
function FormatSeconds(const AValue: Double): string; overload;
|
|
function FormatSeconds(const AValue: Double): string; overload;
|
|
|
|
|
|
|
|
+/// <summary>
|
|
|
|
+/// 是否中国手机号
|
|
|
|
+/// 13900000000
|
|
|
|
+/// +8613900000000
|
|
|
|
+/// +86 139 0000 0000
|
|
|
|
+/// +86-139-0000-0000
|
|
|
|
+/// </summary>
|
|
|
|
+/// <param name="AOnlyNum">仅允许数字和开头的+</param>
|
|
|
|
+function IsChineseMobileNumber(S: string; AOnlyNum: Boolean = False): Boolean;
|
|
|
|
+
|
|
implementation
|
|
implementation
|
|
|
|
|
|
uses
|
|
uses
|
|
- System.Classes, System.SysUtils, System.IOUtils;
|
|
|
|
|
|
+ Classes, SysUtils, IOUtils;
|
|
|
|
|
|
function CreateBlankFile(S: string): Boolean;
|
|
function CreateBlankFile(S: string): Boolean;
|
|
var
|
|
var
|
|
@@ -124,4 +134,40 @@ begin
|
|
FormatSeconds(Int64(AValue));
|
|
FormatSeconds(Int64(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function IsChineseMobileNumber(S: string; AOnlyNum: Boolean): boolean;
|
|
|
|
+var
|
|
|
|
+ p: PChar;
|
|
|
|
+ i: Integer;
|
|
|
|
+begin
|
|
|
|
+ Result := False;
|
|
|
|
+
|
|
|
|
+ // 最短肯定是11位
|
|
|
|
+ if (Length(S) < 11) then
|
|
|
|
+ Exit;
|
|
|
|
+
|
|
|
|
+ i := 0;
|
|
|
|
+ p := PChar(S);
|
|
|
|
+ while p^ <> #0 do begin
|
|
|
|
+ if p^ = '+' then begin
|
|
|
|
+ if i > 0 then // +号必须在第一位
|
|
|
|
+ Exit;
|
|
|
|
+ if (p[1] = '8') and (p[2] = '6') then // +86,而且是连续的
|
|
|
|
+ Inc(p, 3)
|
|
|
|
+ else
|
|
|
|
+ Exit;
|
|
|
|
+ end
|
|
|
|
+ else if ((p^ >= '0') and (p^ <= '9')) then begin
|
|
|
|
+ if (i = 0) and (p^ <> '1') then // 中国手机号都是1开头
|
|
|
|
+ Exit;
|
|
|
|
+ Inc(p);
|
|
|
|
+ Inc(i);
|
|
|
|
+ end
|
|
|
|
+ else if (not AOnlyNum) and ((p^ = '-') or (p^ = ' ')) then
|
|
|
|
+ Inc(p)
|
|
|
|
+ else
|
|
|
|
+ Exit;
|
|
|
|
+ end;
|
|
|
|
+ Result := i = 11; //中国手机号 11位
|
|
|
|
+end;
|
|
|
|
+
|
|
end.
|
|
end.
|