//校验手机号
function
IsMobileNumber( num:
string
):
boolean
;
begin
Result:=
False
;
if
length( trim( Num ) ) <>
11
then
Exit;
if
( ( copy( num,
1
,
2
) <>
‘13‘
)
and
( copy( num ,
1
,
2
) <>
‘15‘
) )
then
Exit;
try
StrToInt( copy( num,
3
,
9
) );
Result:=
True
;
except
end
;
end
;
Verify the ID, return the character 1 legally, otherwise return the format error message
function validatepid (const apid:string): string;
{intrinsic function, take the ID number check bit, last one, valid for 18 bits}
function Getverifybit (sidentitynum:string): Char;
Var
Nnum:integer;
Begin
Result: = #0;
Nnum: = Strtoint (sidentitynum[1]) * 7
Strtoint (Sidentitynum[2]) * 9
Strtoint (Sidentitynum[3]) * 10
Strtoint (Sidentitynum[4]) * 5
Strtoint (Sidentitynum[5]) * 8
Strtoint (Sidentitynum[6]) * 4
Strtoint (Sidentitynum[7]) * 2
Strtoint (Sidentitynum[8]) * 1
Strtoint (Sidentitynum[9]) * 6
Strtoint (sidentitynum[10]) * 3
Strtoint (sidentitynum[11]) * 7
Strtoint (sidentitynum[12]) * 9
Strtoint (sidentitynum[13]) * 10
Strtoint (sidentitynum[14]) * 5
Strtoint (sidentitynum[15]) * 8
Strtoint (sidentitynum[16]) * 4
Strtoint (sidentitynum[17]) * 2;
Nnum: = nnum mod 11;
Case Nnum of
0:result: = ' 1 ';
1:result: = ' 0 ';
2:result: = ' X ';
3:result: = ' 9 ';
4:result: = ' 8 ';
5:result: = ' 7 ';
6:result: = ' 6 ';
7:result: = ' 5 ';
8:result: = ' 4 ';
9:result: = ' 3 ';
10:result: = ' 2 ';
End
End
Var
L:integer;
scentury:string;
Syear2bit, syear4bit:string;
smonth:string;
sdate:string;
Icentury:integer;
Imonth:integer;
Idate:integer;
crcfact:string; The actual value of the 18-digit card number
crcth:string; The theoretical value of the 18-digit card number
Febdayamt:byte; February days
Begin
L: = Length (APID);
if (L in [+]) = False Then
Begin
Result: = Format (' ID number is not 15-bit or 18-bit (%0:s, actual number of digits:%1:d) ', [APID, L]);
Exit;
End
Crcfact: = ";
If L =
Begin
Scentury: = Copy (APID, 7, 2);
Icentury: = Strtoint (Scentury);
if (Icentury in [18..20]) = False Then
Begin
Result: = Format (' ID number is invalid: the first two digits of the 18-digit certificate number must be between 18-20 (%0:s) ', [Scentury]);
Exit;
End
Syear2bit: = Copy (APID, 9, 2);
Syear4bit: = Scentury syear2bit;
Smonth: = Copy (APID, 11, 2);
Sdate: = Copy (APID, 13, 2);
Crcfact: = Copy (APID, 18, 1);
End Else
Begin
Scentury: = ' 19 ';
Syear2bit: = Copy (APID, 7, 2);
Syear4bit: = Scentury syear2bit;
Smonth: = Copy (APID, 9, 2);
Sdate: = Copy (APID, 11, 2);
End
Imonth: = Strtoint (Smonth);
IDate: = Strtoint (sdate);
if (imonth in [01..12]) = False Then
Begin
Result: = Format (' Invalid ID number: Month must be between 01-12 (%0:s) ', [Smonth]);
Exit;
End
if (imonth in [1, 3, 5, 7, 8, and ten]) then
Begin
if (iDate in [01..31]) = False Then
Begin
Result: = Format (' Invalid ID number: Invalid date, cannot be zero or exceeds maximum value for the month (%0:s) ', [sdate]);
Exit;
End
End
if (Imonth in [4, 6, 9, one-by-one]) then
Begin
if (iDate in [01..30]) = False Then
Begin
Result: = Format (' Invalid ID number: Invalid date, cannot be zero or exceeds maximum value for the month (%0:s) ', [sdate]);
Exit;
End
End
If Isleapyear (Strtoint (Scentury syear2bit)) = True Then
Begin
Febdayamt: = 29;
End Else
Begin
Febdayamt: = 28;
End
if (Imonth in [2]) then
Begin
if (iDate in [01..FebDayAmt]) = False Then
Begin
Result: = Format (' Invalid ID number: Invalid date, cannot be zero or exceeds maximum value for the month (%0:s) ', [sdate]);
Exit;
End
End
If Crcfact <> ' then
Begin
CRCTH: = Getverifybit (APID);
If Crcfact <> Crcth Then
Begin
Result: = Format (' Invalid ID number: Check digit (18th bit) Error: (%0:s) ', [APID]);
Exit;
End
End
Result: = ' 1 ';
End
Delphi: Check mobile phone number and ID number