-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdgii-valid.js
72 lines (64 loc) · 1.55 KB
/
dgii-valid.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
69
70
71
72
/**
* @param {string} RNC
* @returns {string} RNC
*/
function clearRNC (RNC = "") {
return RNC.replace(/\D/g,'');
}
/**
* @param {string} NCF
* @returns {string} NCF
*/
function clearNCF (NCF = "") {
return NCF.replace(/[^BE0-9]/g, '');
}
/**
* @param {string} CarPlate
* @returns {string} CarPlate
*/
function clearCarPlate (CarPlate = "") {
return CarPlate.replace(/[^A-Z0-9]/gi, '');
}
/**
* @param {string} RNC
* @returns {boolean} isRNC
*/
function isRNC(Rnc=""){
Rnc = clearRNC(Rnc);
const rncRegex = /^[0-9]{9,11}$/;
return rncRegex.test(Rnc);
}
/**
* @param {string} ENCF
* @returns {boolean} isENCF
*/
function isENCF(ENCF = "") {
ENCF = clearNCF(ENCF);
const ncfRegex = /^E(?:3[1-4]{1}|41|4[3-7]{1})[0-9]{10}$/;
return ncfRegex.test(ENCF);
}
/**
* @param {string} NCF
* @returns {boolean} isNCF
*/
function isNCF(NCF = "") {
NCF = clearNCF(NCF);
const ncfRegex = /^B(?:0[1-4]{1}|1[1-7]{1})[0-9]{8}$/;
return ncfRegex.test(NCF);
}
function isCarPlate(CarPlate=""){
clearCarPlate(CarPlate)
const regexPlaca = /^(A|AA|B|C|D|F|G|L|H|I|T|P|U|J|R|S|M|OE|OF|OM|OP|EA|EG|EL|EM|ED|EI|VC|WD|OI|EX|YX|Z|NZ|DD|PP|K)\d{4,6}$/i;
return regexPlaca.test(CarPlate);
}
function isSecureCode(Code=""){
const secureCodeRegex = /^[a-zA-Z0-9]{6}$/;
return secureCodeRegex.test(Code);
}
exports.clearRNC = clearRNC;
exports.clearNCF = clearNCF;
exports.clearCarPlate = clearCarPlate;
exports.isRNC = isRNC;
exports.isENCF = isENCF;
exports.isNCF = isNCF
module.exports = { clearRNC, clearNCF,clearCarPlate, isRNC , isENCF, isNCF, isCarPlate, isSecureCode};