PeopleSoft-(系统标准)证件格式校验函数

配置页面

参数说明:“.”、“-”号用来隔离位数;“9”表示数字;“X”表示字母;

系统标准-身份证格式校验函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/******************************************************
Function : CheckNID_General
Purpose : Check format of NATIONAL_ID against definition in NID_TYPE_TBL
Version : 26.8.03
Parameters : &NATIONAL_ID, &NID_TYPE, &COUNTRY
Returns :
******************************************************/
Function CheckNID_General(&NATIONAL_ID, &NID_TYPE, &COUNTRY, &NIDFormat);

Local string &Alpha, &Alpha_xz, &Numeric, &TestChar, &MaskChar;
Local number &iNID, &LengthNID;
Local boolean &IsFormatError;

&Alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
&Alpha_xz = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
&Numeric = "1234567890";
&AlphaNum_SGP = &Alpha | &Numeric | "-";
&IsFormatError = False;

If All(&NATIONAL_ID) Then
If All(&NIDFormat) Then
&LengthNID = Len(&NIDFormat);

If &COUNTRY = "MYS" Then
&Alpha = &Alpha | " ";
If &NID_TYPE <> "NEWIC" Then
&LengthNID = Len(&NATIONAL_ID);
End-If;
End-If;

If Len(&NATIONAL_ID) > &LengthNID Then
/* Incorrect Length */
&IsFormatError = True;
End-If;

&K = 0;
For &J = 1 To &LengthNID
&ChkChar = Substring(&NIDFormat, &J, 1);
If &ChkChar = "X" Or
&MaskChar = "Z" Then
&K = &K + 1;
End-If;
End-For;

/* BUG: 13702638 start */
If &K <> Len(&NATIONAL_ID) Or
&K <> &LengthNID Then
/* BUG: 13702638 end */
&iNID = 1;
While &iNID <= &LengthNID And
Not &IsFormatError
&TestChar = Substring(&NATIONAL_ID, &iNID, 1);
&MaskChar = Substring(&NIDFormat, &iNID, 1);

Evaluate &MaskChar
When = "X"
When = "Z"
/* Any Alpha or Numeric character is acceptable */
If Find(&TestChar, &Numeric) <> 0 Or
Find(&TestChar, &Alpha_xz) <> 0 Then
&IsFormatError = False;
Else
&IsFormatError = True;
End-If;
Break;
When = "9"
/* Must be Numeric */
If Find(&TestChar, &Numeric) = 0 Then
&IsFormatError = True;
End-If;
Break;
When = "D"
/* Must be AlphaNumeric or "-" */
If Find(&TestChar, &AlphaNum_SGP) = 0 Then
&IsFormatError = True;
End-If;
Break;
When = "A"
/* Must be Alpha */
If Find(&TestChar, &Alpha) = 0 Then
&IsFormatError = True;
End-If;
Break;
When-Other
/* Special: must be equal to the mask character */
If &TestChar <> &MaskChar Then
&IsFormatError = True;
End-If;
Break;
End-Evaluate;
&iNID = &iNID + 1;
End-While;
End-If;

If &IsFormatError Then

If &ValidateServiceCall Then
throw create HCR_PERSON_EXCEPTIONS:PersonExceptions:ValidateNIDExceptions_v1_0:NIDFormatException( Null, &NID_TYPE, &COUNTRY, &NIDFormat);
Else
/* "The format of the National ID Type %1 for country %2 has to be %3." */
Error (MsgGet(1000, 490, "Message Not Found", &NID_TYPE, &COUNTRY, &NIDFormat));
End-If;
End-If;
End-If;
End-If;
End-Function;

使用方法

1
2
3
4
5
//函数引用申明 
Declare Function CheckNID_General PeopleCode FUNCLIB_HR.NATIONAL_ID FieldFormula;
//传入参数调用方法
CheckNID_General(C_PREHIRE0_TBL.NID_SPECIAL_CHAR.Value, C_PREHIRE0_TBL.NATIONAL_ID_TYPE.Value, C_PREHIRE0_TBL.COUNTRY.Value, &strNATIONAL_ID_FORMAT);