Skip to content

Commit bf9d917

Browse files
committed
v0.1.0 add visa and master card validator.
1 parent f8134ab commit bf9d917

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ validator.isEmail('abc@gmail.com'); // => true
3636
- isAllDigit(str): check if it is a string only contains digits
3737
- isChineseTel(str): check if it is a Chinese cell-phone number
3838
- isChineseIdCard(str): check if it is a 18-digit Chinese ID card number
39+
- isVisaCard(str): check if it is a Visa card
40+
- isMasterCard(str): check if it is a Master card
3941

4042
## Test
4143

lib/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ module.exports = {
9595

9696
return temp[17] === validCodeArr[sum % 11];
9797
}
98+
},
99+
100+
/**
101+
* check if it is a Visa card
102+
* @param str
103+
* @returns {boolean}
104+
*/
105+
isVisaCard: function (str) {
106+
return /^4[0-9]{12}(?:[0-9]{3})?$/.test(str);
107+
},
108+
109+
/**
110+
* check if it is a Master card
111+
* @param str
112+
* @returns {boolean}
113+
*/
114+
isMasterCard: function (str) {
115+
return /^5[1-5][0-9]{14}$/.test(str);
98116
}
99117

100118
};

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.0.3",
3+
"version": "0.1.0",
44
"description": "String validator for more",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)