-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorgCode.js
68 lines (62 loc) · 1.39 KB
/
orgCode.js
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
/**
* 生成组织机构代码
*/
function generatorOrgCode(){
var max = 99999999;
var min = 10000000;
var num = parseInt(((Math.random()*(max-min))+min));
var ws = [ 3, 7, 9, 10, 5, 8, 4, 2 ];
var sum = 0;
for (var i = 0; i < 8; i++) {
sum += (num+"").charAt(i)* ws[i];
}
var C9 = 11 - (sum % 11);
if (C9 == 11) {
C9 = '0';
} else if (C9 == 10) {
C9 = 'X';
} else {
C9 = C9 + '';
}
$("#orgCode").val(num+"-"+C9);
}
/**
* 验证组织机构合法性方法
*/
function orgCodeValidate(value) {
toastr.options.positionClass = 'toast-center-center';
toastr.options.timeOut = 1000;
if (value.trim() != "") {
var values = value.split("-");
var ws = [ 3, 7, 9, 10, 5, 8, 4, 2 ];
var str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var reg = /^([0-9A-Z]){8}$/;
if (!reg.test(values[0])) {
toastr.warning('错误的组织机构代码!');
return false;
}
var sum = 0;
for (var i = 0; i < 8; i++) {
sum += str.indexOf(values[0].charAt(i)) * ws[i];
}
var C9 = 11 - (sum % 11);
var YC9 = values[1] + '';
if (C9 == 11) {
C9 = '0';
} else if (C9 == 10) {
C9 = 'X';
} else {
C9 = C9 + '';
}
if(YC9 == C9){
toastr.info('正确的组织机构代码!');
return true;
}else{
toastr.warning('错误的组织机构代码!');
return false;
}
}else{
toastr.warning('请生成或者输入组织机构代码!');
return false;
}
}