summaryrefslogtreecommitdiff
path: root/src/node_modules/validator/es/lib/isPassportNumber.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
committerMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
commit46e43f4bde4a35785b4997b81e86cd19f046b69b (patch)
treec53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/validator/es/lib/isPassportNumber.js
downloadlangdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip
Commit
Diffstat (limited to 'src/node_modules/validator/es/lib/isPassportNumber.js')
-rw-r--r--src/node_modules/validator/es/lib/isPassportNumber.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/node_modules/validator/es/lib/isPassportNumber.js b/src/node_modules/validator/es/lib/isPassportNumber.js
new file mode 100644
index 0000000..3810da0
--- /dev/null
+++ b/src/node_modules/validator/es/lib/isPassportNumber.js
@@ -0,0 +1,104 @@
+/**
+ * Reference:
+ * https://en.wikipedia.org/ -- Wikipedia
+ * https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
+ * https://countrycode.org/ -- Country Codes
+ */
+var passportRegexByCountryCode = {
+ AM: /^[A-Z]{2}\d{7}$/,
+ // ARMENIA
+ AR: /^[A-Z]{3}\d{6}$/,
+ // ARGENTINA
+ AT: /^[A-Z]\d{7}$/,
+ // AUSTRIA
+ AU: /^[A-Z]\d{7}$/,
+ // AUSTRALIA
+ BE: /^[A-Z]{2}\d{6}$/,
+ // BELGIUM
+ BG: /^\d{9}$/,
+ // BULGARIA
+ CA: /^[A-Z]{2}\d{6}$/,
+ // CANADA
+ CH: /^[A-Z]\d{7}$/,
+ // SWITZERLAND
+ CN: /^[GE]\d{8}$/,
+ // CHINA [G=Ordinary, E=Electronic] followed by 8-digits
+ CY: /^[A-Z](\d{6}|\d{8})$/,
+ // CYPRUS
+ CZ: /^\d{8}$/,
+ // CZECH REPUBLIC
+ DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
+ // GERMANY
+ DK: /^\d{9}$/,
+ // DENMARK
+ DZ: /^\d{9}$/,
+ // ALGERIA
+ EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
+ // ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
+ ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
+ // SPAIN
+ FI: /^[A-Z]{2}\d{7}$/,
+ // FINLAND
+ FR: /^\d{2}[A-Z]{2}\d{5}$/,
+ // FRANCE
+ GB: /^\d{9}$/,
+ // UNITED KINGDOM
+ GR: /^[A-Z]{2}\d{7}$/,
+ // GREECE
+ HR: /^\d{9}$/,
+ // CROATIA
+ HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
+ // HUNGARY
+ IE: /^[A-Z0-9]{2}\d{7}$/,
+ // IRELAND
+ IS: /^(A)\d{7}$/,
+ // ICELAND
+ IT: /^[A-Z0-9]{2}\d{7}$/,
+ // ITALY
+ JP: /^[A-Z]{2}\d{7}$/,
+ // JAPAN
+ KR: /^[MS]\d{8}$/,
+ // SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
+ LT: /^[A-Z0-9]{8}$/,
+ // LITHUANIA
+ LU: /^[A-Z0-9]{8}$/,
+ // LUXEMBURG
+ LV: /^[A-Z0-9]{2}\d{7}$/,
+ // LATVIA
+ MT: /^\d{7}$/,
+ // MALTA
+ NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
+ // NETHERLANDS
+ PO: /^[A-Z]{2}\d{7}$/,
+ // POLAND
+ PT: /^[A-Z]\d{6}$/,
+ // PORTUGAL
+ RO: /^\d{8,9}$/,
+ // ROMANIA
+ SE: /^\d{8}$/,
+ // SWEDEN
+ SL: /^(P)[A-Z]\d{7}$/,
+ // SLOVANIA
+ SK: /^[0-9A-Z]\d{7}$/,
+ // SLOVAKIA
+ TR: /^[A-Z]\d{8}$/,
+ // TURKEY
+ UA: /^[A-Z]{2}\d{6}$/,
+ // UKRAINE
+ US: /^\d{9}$/ // UNITED STATES
+
+};
+/**
+ * Check if str is a valid passport number
+ * relative to provided ISO Country Code.
+ *
+ * @param {string} str
+ * @param {string} countryCode
+ * @return {boolean}
+ */
+
+export default function isPassportNumber(str, countryCode) {
+ /** Remove All Whitespaces, Convert to UPPERCASE */
+ var normalizedStr = str.replace(/\s/g, '').toUpperCase();
+ return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
+} \ No newline at end of file