Skip to content

Commit d644379

Browse files
committed
Version 1.0.0
1. Fix bug of `isChineseIdCard` 2. Add more test case.
1 parent e05f7b8 commit d644379

4 files changed

Lines changed: 48 additions & 7 deletions

File tree

example/example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ console.log(validator.isAllEnglish('test'));
2323
console.log(validator.isAllDigit('12345'));
2424

2525
// isChineseIdCard
26-
console.log(validator.isChineseIdCard('330682199110273013'));
26+
console.log(validator.isChineseIdCard('15210319861215033x'));

lib/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ module.exports = {
7272
var year = num.substring(6, 10);
7373
var month = num.substring(10, 12);
7474
var day = num.substring(12, 14);
75-
var temp = new Date(year, parseInt(month, 10), parseInt(day, 10));
75+
var temp = new Date(year, parseInt(month, 10) - 1, parseInt(day, 10));
7676

7777
return (temp.getFullYear() === parseInt(year, 10) &&
78-
temp.getMonth() === parseInt(month, 10) &&
78+
temp.getMonth() + 1 === parseInt(month, 10) &&
7979
temp.getDate() === parseInt(day, 10));
8080
}
8181

@@ -89,11 +89,11 @@ module.exports = {
8989
temp[17] = 10;
9090
}
9191

92-
for (var i = 0; i < temp.length; i++) {
92+
for (var i = 0; i < temp.length - 1; i++) {
9393
sum += wc[i] * temp[i];
9494
}
9595

96-
return temp[17] === validCodeArr[sum % 11];
96+
return temp[17] == validCodeArr[sum % 11];
9797
}
9898
},
9999

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "is-valid",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"description": "String validator for more",
55
"main": "index.js",
66
"scripts": {

test/test.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @description
66
* @author Fantasy <fantasyshao@icloud.com>
77
* @create 2014-09-10
8-
* @update 2014-09-10
8+
* @update 2014-09-16
99
*/
1010

1111
var validator = require('../index');
@@ -142,4 +142,45 @@ describe('Validate', function () {
142142
});
143143
});
144144

145+
describe('#isVisaCard', function () {
146+
it('should validate a Visa card', function () {
147+
test({
148+
validator: 'isVisaCard',
149+
valid: [
150+
'4012888888881881',
151+
'4111111111111111',
152+
'4222222222222'
153+
],
154+
invalid: [
155+
// mess
156+
'1234567891012312',
157+
// JCB
158+
'3566002020360505',
159+
// Master Card
160+
'5555555555554444'
161+
]
162+
});
163+
});
164+
});
165+
166+
describe('#isMasterCard', function () {
167+
it('should validate a Master card', function () {
168+
test({
169+
validator: 'isMasterCard',
170+
valid: [
171+
'5555555555554444',
172+
'5105105105105100'
173+
],
174+
invalid: [
175+
// mess
176+
'1234567891012312',
177+
// JCB
178+
'3566002020360505',
179+
// Visa
180+
'4012888888881881'
181+
]
182+
});
183+
});
184+
});
185+
145186
});

0 commit comments

Comments
 (0)