-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
regex-validate-pin-code.js
36 lines (32 loc) · 1.08 KB
/
regex-validate-pin-code.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
function validatePIN(pin) {
const is4Digits = /^\d\d\d\d$/.test(pin);
const is6Digits = /^\d\d\d\d\d\d$/.test(pin);
return is4Digits || is6Digits;
}
function validatePIN(pin) {
return /^\d\d\d\d$|^\d\d\d\d\d\d$/.test(pin);
}
function validatePIN(pin) {
return /^(\d\d\d\d|\d\d\d\d\d\d)$/.test(pin);
}
function validatePIN(pin) {
return /^(\d{4}|\d{6})$/.test(pin);
}
console.log(validatePIN('1'),false);
console.log(validatePIN('12'),false);
console.log(validatePIN('123'),false);
console.log(validatePIN('12345'),false);
console.log(validatePIN('1234567'),false);
console.log(validatePIN('-1234'),false);
console.log(validatePIN('1.234'),false);
console.log(validatePIN('-1.234'),false);
console.log(validatePIN('00000000'),false);
console.log(validatePIN('1234'),true);
console.log(validatePIN('0000'),true);
console.log(validatePIN('1111'),true);
console.log(validatePIN('123456'),true);
console.log(validatePIN('098765'),true);
console.log(validatePIN('000000'),true);
console.log(validatePIN('123456'),true);
console.log(validatePIN('090909'),true);
console.log(validatePIN(12345),true);