isMobilePhone.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isMobilePhone;
  6. exports.locales = void 0;
  7. var _assertString = _interopRequireDefault(require("./util/assertString"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /* eslint-disable max-len */
  10. var phones = {
  11. 'am-AM': /^(\+?374|0)((10|[9|7][0-9])\d{6}$|[2-4]\d{7}$)/,
  12. 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
  13. 'ar-BH': /^(\+?973)?(3|6)\d{7}$/,
  14. 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
  15. 'ar-LB': /^(\+?961)?((3|81)\d{6}|7\d{7})$/,
  16. 'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
  17. 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/,
  18. 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/,
  19. 'ar-KW': /^(\+?965)[569]\d{7}$/,
  20. 'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/,
  21. 'ar-MA': /^(?:(?:\+|00)212|0)[5-7]\d{8}$/,
  22. 'ar-OM': /^((\+|00)968)?(9[1-9])\d{6}$/,
  23. 'ar-PS': /^(\+?970|0)5[6|9](\d{7})$/,
  24. 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
  25. 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
  26. 'ar-TN': /^(\+?216)?[2459]\d{7}$/,
  27. 'az-AZ': /^(\+994|0)(5[015]|7[07]|99)\d{7}$/,
  28. 'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/,
  29. 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
  30. 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
  31. 'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/,
  32. 'ca-AD': /^(\+376)?[346]\d{5}$/,
  33. 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  34. 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
  35. 'de-DE': /^((\+49|0)[1|3])([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7,9}$/,
  36. 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
  37. 'de-CH': /^(\+41|0)([1-9])\d{1,9}$/,
  38. 'de-LU': /^(\+352)?((6\d1)\d{6})$/,
  39. 'dv-MV': /^(\+?960)?(7[2-9]|91|9[3-9])\d{7}$/,
  40. 'el-GR': /^(\+?30|0)?(69\d{8})$/,
  41. 'en-AU': /^(\+?61|0)4\d{8}$/,
  42. 'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}))/,
  43. 'en-GB': /^(\+?44|0)7\d{9}$/,
  44. 'en-GG': /^(\+?44|0)1481\d{6}$/,
  45. 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28|55|59)\d{7}$/,
  46. 'en-GY': /^(\+592|0)6\d{6}$/,
  47. 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/,
  48. 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/,
  49. 'en-IE': /^(\+?353|0)8[356789]\d{7}$/,
  50. 'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
  51. 'en-KE': /^(\+?254|0)(7|1)\d{8}$/,
  52. 'en-KI': /^((\+686|686)?)?( )?((6|7)(2|3|8)[0-9]{6})$/,
  53. 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/,
  54. 'en-MU': /^(\+?230|0)?\d{8}$/,
  55. 'en-NA': /^(\+?264|0)(6|8)\d{7}$/,
  56. 'en-NG': /^(\+?234|0)?[789]\d{9}$/,
  57. 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
  58. 'en-PK': /^((00|\+)?92|0)3[0-6]\d{8}$/,
  59. 'en-PH': /^(09|\+639)\d{9}$/,
  60. 'en-RW': /^(\+?250|0)?[7]\d{8}$/,
  61. 'en-SG': /^(\+65)?[3689]\d{7}$/,
  62. 'en-SL': /^(\+?232|0)\d{8}$/,
  63. 'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
  64. 'en-UG': /^(\+?256|0)?[7]\d{8}$/,
  65. 'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,
  66. 'en-ZA': /^(\+?27|0)\d{9}$/,
  67. 'en-ZM': /^(\+?26)?09[567]\d{7}$/,
  68. 'en-ZW': /^(\+263)[0-9]{9}$/,
  69. 'en-BW': /^(\+?267)?(7[1-8]{1})\d{6}$/,
  70. 'es-AR': /^\+?549(11|[2368]\d)\d{8}$/,
  71. 'es-BO': /^(\+?591)?(6|7)\d{7}$/,
  72. 'es-CO': /^(\+?57)?3(0(0|1|2|4|5)|1\d|2[0-4]|5(0|1))\d{7}$/,
  73. 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
  74. 'es-CR': /^(\+506)?[2-8]\d{7}$/,
  75. 'es-CU': /^(\+53|0053)?5\d{7}/,
  76. 'es-DO': /^(\+?1)?8[024]9\d{7}$/,
  77. 'es-HN': /^(\+?504)?[9|8]\d{7}$/,
  78. 'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/,
  79. 'es-ES': /^(\+?34)?[6|7]\d{8}$/,
  80. 'es-PE': /^(\+?51)?9\d{8}$/,
  81. 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
  82. 'es-PA': /^(\+?507)\d{7,8}$/,
  83. 'es-PY': /^(\+?595|0)9[9876]\d{7}$/,
  84. 'es-SV': /^(\+?503)?[67]\d{7}$/,
  85. 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/,
  86. 'es-VE': /^(\+?58)?(2|4)\d{9}$/,
  87. 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,
  88. 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
  89. 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/,
  90. 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/,
  91. 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  92. 'fr-BF': /^(\+226|0)[67]\d{7}$/,
  93. 'fr-CM': /^(\+?237)6[0-9]{8}$/,
  94. 'fr-FR': /^(\+?33|0)[67]\d{8}$/,
  95. 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/,
  96. 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/,
  97. 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/,
  98. 'fr-PF': /^(\+?689)?8[789]\d{6}$/,
  99. 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/,
  100. 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,
  101. 'hu-HU': /^(\+?36|06)(20|30|31|50|70)\d{7}$/,
  102. 'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
  103. 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
  104. 'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/,
  105. 'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
  106. 'ka-GE': /^(\+?995)?(5|79)\d{7}$/,
  107. 'kk-KZ': /^(\+?7|8)?7\d{9}$/,
  108. 'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
  109. 'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
  110. 'lt-LT': /^(\+370|8)\d{8}$/,
  111. 'lv-LV': /^(\+?371)2\d{7}$/,
  112. 'ms-MY': /^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
  113. 'mz-MZ': /^(\+?258)?8[234567]\d{7}$/,
  114. 'nb-NO': /^(\+?47)?[49]\d{7}$/,
  115. 'ne-NP': /^(\+?977)?9[78]\d{8}$/,
  116. 'nl-BE': /^(\+?32|0)4\d{8}$/,
  117. 'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
  118. 'nn-NO': /^(\+?47)?[49]\d{7}$/,
  119. 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
  120. 'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[2-9]{1}\d{3}\-?\d{4}))$/,
  121. 'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
  122. 'pt-AO': /^(\+244)\d{9}$/,
  123. 'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,
  124. 'ru-RU': /^(\+?7|8)?9\d{9}$/,
  125. 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|4|5|6|7|8)( |-)?)\d{7}$/,
  126. 'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,
  127. 'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  128. 'sq-AL': /^(\+355|0)6[789]\d{6}$/,
  129. 'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
  130. 'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,
  131. 'tg-TJ': /^(\+?992)?[5][5]\d{7}$/,
  132. 'th-TH': /^(\+66|66|0)\d{9}$/,
  133. 'tr-TR': /^(\+?90|0)?5\d{9}$/,
  134. 'tk-TM': /^(\+993|993|8)\d{8}$/,
  135. 'uk-UA': /^(\+?38|8)?0\d{9}$/,
  136. 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/,
  137. 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/,
  138. 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/,
  139. 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/,
  140. 'dz-BT': /^(\+?975|0)?(17|16|77|02)\d{6}$/
  141. };
  142. /* eslint-enable max-len */
  143. // aliases
  144. phones['en-CA'] = phones['en-US'];
  145. phones['fr-CA'] = phones['en-CA'];
  146. phones['fr-BE'] = phones['nl-BE'];
  147. phones['zh-HK'] = phones['en-HK'];
  148. phones['zh-MO'] = phones['en-MO'];
  149. phones['ga-IE'] = phones['en-IE'];
  150. phones['fr-CH'] = phones['de-CH'];
  151. phones['it-CH'] = phones['fr-CH'];
  152. function isMobilePhone(str, locale, options) {
  153. (0, _assertString.default)(str);
  154. if (options && options.strictMode && !str.startsWith('+')) {
  155. return false;
  156. }
  157. if (Array.isArray(locale)) {
  158. return locale.some(function (key) {
  159. // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
  160. // istanbul ignore else
  161. if (phones.hasOwnProperty(key)) {
  162. var phone = phones[key];
  163. if (phone.test(str)) {
  164. return true;
  165. }
  166. }
  167. return false;
  168. });
  169. } else if (locale in phones) {
  170. return phones[locale].test(str); // alias falsey locale as 'any'
  171. } else if (!locale || locale === 'any') {
  172. for (var key in phones) {
  173. // istanbul ignore else
  174. if (phones.hasOwnProperty(key)) {
  175. var phone = phones[key];
  176. if (phone.test(str)) {
  177. return true;
  178. }
  179. }
  180. }
  181. return false;
  182. }
  183. throw new Error("Invalid locale '".concat(locale, "'"));
  184. }
  185. var locales = Object.keys(phones);
  186. exports.locales = locales;