Function sfz
Parameters cNumber
#Define InvalidSize "身份证号码长度不正确!"
#Define InvalidChar "身份证号码包括非法字符!"
#Define InvalidDate "出生日期无效!"
#Define InvalidReturnValue ".F."
Private cString
Do Case
Case Len(cNumber) = 15
cString = Stuff(cNumber,7,0,"19")
Case Len(cNumber) = 18
cString =Left(Alltrim(cNumber),17)
Otherwise
Messagebox(InvalidSize,48,"信息提示")
Return InvalidReturnValue
Endcase
Private i,N,iRet
Store 0 To iRet
For i = 1 To 17
N = Substr(cString,i,1)
If Not Isdigit(N)
Messagebox(invalidChar,48,"信息提示")
Return invalidReturnValue
Endif
N = 2 ^ (18 - i) % 11 * Val(N)
iRet = iRet + N
Endfor
iRet = iRet % 11 + 1
Private oldDateSet, oldCentury
Private oldStrictDate, BirthDay
oldDateSet = Set("DATE")
oldCentury = Set("CENTURY")
oldStrictDate = Set("STRICTDATE")
Set Date Ansi
Set Century On
Set StrictDate To 0
BirthDay = Ctod(Substr(cString,7,4)+"-"+Substr(cString,11,2)+"-"+Substr(cString,13,2))
Set StrictDate To &oldStrictDate
Set Century &oldCentury
Set Date &oldDateSet
If Empty(BirthDay)
Messagebox(InvalidDate,48,"信息提示")
Return InvalidReturnValue
Endif
Return cString+Substr("10x98765432",iRet,1)
Endfunc
Parameters cNumber
#Define InvalidSize "身份证号码长度不正确!"
#Define InvalidChar "身份证号码包括非法字符!"
#Define InvalidDate "出生日期无效!"
#Define InvalidReturnValue ".F."
Private cString
Do Case
Case Len(cNumber) = 15
cString = Stuff(cNumber,7,0,"19")
Case Len(cNumber) = 18
cString =Left(Alltrim(cNumber),17)
Otherwise
Messagebox(InvalidSize,48,"信息提示")
Return InvalidReturnValue
Endcase
Private i,N,iRet
Store 0 To iRet
For i = 1 To 17
N = Substr(cString,i,1)
If Not Isdigit(N)
Messagebox(invalidChar,48,"信息提示")
Return invalidReturnValue
Endif
N = 2 ^ (18 - i) % 11 * Val(N)
iRet = iRet + N
Endfor
iRet = iRet % 11 + 1
Private oldDateSet, oldCentury
Private oldStrictDate, BirthDay
oldDateSet = Set("DATE")
oldCentury = Set("CENTURY")
oldStrictDate = Set("STRICTDATE")
Set Date Ansi
Set Century On
Set StrictDate To 0
BirthDay = Ctod(Substr(cString,7,4)+"-"+Substr(cString,11,2)+"-"+Substr(cString,13,2))
Set StrictDate To &oldStrictDate
Set Century &oldCentury
Set Date &oldDateSet
If Empty(BirthDay)
Messagebox(InvalidDate,48,"信息提示")
Return InvalidReturnValue
Endif
Return cString+Substr("10x98765432",iRet,1)
Endfunc