isPassportNumber.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isPassportNumber;
  6. var _assertString = _interopRequireDefault(require("./util/assertString"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. /**
  9. * Reference:
  10. * https://en.wikipedia.org/ -- Wikipedia
  11. * https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
  12. * https://countrycode.org/ -- Country Codes
  13. */
  14. var passportRegexByCountryCode = {
  15. AM: /^[A-Z]{2}\d{7}$/,
  16. // ARMENIA
  17. AR: /^[A-Z]{3}\d{6}$/,
  18. // ARGENTINA
  19. AT: /^[A-Z]\d{7}$/,
  20. // AUSTRIA
  21. AU: /^[A-Z]\d{7}$/,
  22. // AUSTRALIA
  23. BE: /^[A-Z]{2}\d{6}$/,
  24. // BELGIUM
  25. BG: /^\d{9}$/,
  26. // BULGARIA
  27. BR: /^[A-Z]{2}\d{6}$/,
  28. // BRAZIL
  29. BY: /^[A-Z]{2}\d{7}$/,
  30. // BELARUS
  31. CA: /^[A-Z]{2}\d{6}$/,
  32. // CANADA
  33. CH: /^[A-Z]\d{7}$/,
  34. // SWITZERLAND
  35. CN: /^G\d{8}$|^E(?![IO])[A-Z0-9]\d{7}$/,
  36. // CHINA [G=Ordinary, E=Electronic] followed by 8-digits, or E followed by any UPPERCASE letter (except I and O) followed by 7 digits
  37. CY: /^[A-Z](\d{6}|\d{8})$/,
  38. // CYPRUS
  39. CZ: /^\d{8}$/,
  40. // CZECH REPUBLIC
  41. DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
  42. // GERMANY
  43. DK: /^\d{9}$/,
  44. // DENMARK
  45. DZ: /^\d{9}$/,
  46. // ALGERIA
  47. EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
  48. // ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
  49. ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
  50. // SPAIN
  51. FI: /^[A-Z]{2}\d{7}$/,
  52. // FINLAND
  53. FR: /^\d{2}[A-Z]{2}\d{5}$/,
  54. // FRANCE
  55. GB: /^\d{9}$/,
  56. // UNITED KINGDOM
  57. GR: /^[A-Z]{2}\d{7}$/,
  58. // GREECE
  59. HR: /^\d{9}$/,
  60. // CROATIA
  61. HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
  62. // HUNGARY
  63. IE: /^[A-Z0-9]{2}\d{7}$/,
  64. // IRELAND
  65. IN: /^[A-Z]{1}-?\d{7}$/,
  66. // INDIA
  67. ID: /^[A-C]\d{7}$/,
  68. // INDONESIA
  69. IR: /^[A-Z]\d{8}$/,
  70. // IRAN
  71. IS: /^(A)\d{7}$/,
  72. // ICELAND
  73. IT: /^[A-Z0-9]{2}\d{7}$/,
  74. // ITALY
  75. JP: /^[A-Z]{2}\d{7}$/,
  76. // JAPAN
  77. KR: /^[MS]\d{8}$/,
  78. // SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
  79. LT: /^[A-Z0-9]{8}$/,
  80. // LITHUANIA
  81. LU: /^[A-Z0-9]{8}$/,
  82. // LUXEMBURG
  83. LV: /^[A-Z0-9]{2}\d{7}$/,
  84. // LATVIA
  85. LY: /^[A-Z0-9]{8}$/,
  86. // LIBYA
  87. MT: /^\d{7}$/,
  88. // MALTA
  89. MZ: /^([A-Z]{2}\d{7})|(\d{2}[A-Z]{2}\d{5})$/,
  90. // MOZAMBIQUE
  91. MY: /^[AHK]\d{8}$/,
  92. // MALAYSIA
  93. NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
  94. // NETHERLANDS
  95. PL: /^[A-Z]{2}\d{7}$/,
  96. // POLAND
  97. PT: /^[A-Z]\d{6}$/,
  98. // PORTUGAL
  99. RO: /^\d{8,9}$/,
  100. // ROMANIA
  101. RU: /^\d{9}$/,
  102. // RUSSIAN FEDERATION
  103. SE: /^\d{8}$/,
  104. // SWEDEN
  105. SL: /^(P)[A-Z]\d{7}$/,
  106. // SLOVANIA
  107. SK: /^[0-9A-Z]\d{7}$/,
  108. // SLOVAKIA
  109. TR: /^[A-Z]\d{8}$/,
  110. // TURKEY
  111. UA: /^[A-Z]{2}\d{6}$/,
  112. // UKRAINE
  113. US: /^\d{9}$/ // UNITED STATES
  114. };
  115. /**
  116. * Check if str is a valid passport number
  117. * relative to provided ISO Country Code.
  118. *
  119. * @param {string} str
  120. * @param {string} countryCode
  121. * @return {boolean}
  122. */
  123. function isPassportNumber(str, countryCode) {
  124. (0, _assertString.default)(str);
  125. /** Remove All Whitespaces, Convert to UPPERCASE */
  126. var normalizedStr = str.replace(/\s/g, '').toUpperCase();
  127. return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
  128. }
  129. module.exports = exports.default;
  130. module.exports.default = exports.default;