isMobilePhone.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = isMobilePhone;
  6. var _assertString = require('./util/assertString');
  7. var _assertString2 = _interopRequireDefault(_assertString);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. /* eslint-disable max-len */
  10. var phones = {
  11. 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
  12. 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
  13. 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
  14. 'en-US': /^(\+?1)?[2-9]\d{2}[2-9](?!11)\d{6}$/,
  15. 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
  16. 'de-DE': /^(\+?49[ \.\-])?([\(]{1}[0-9]{1,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,
  17. 'da-DK': /^(\+?45)?(\d{8})$/,
  18. 'el-GR': /^(\+?30)?(69\d{8})$/,
  19. 'en-AU': /^(\+?61|0)4\d{8}$/,
  20. 'en-GB': /^(\+?44|0)7\d{9}$/,
  21. 'en-HK': /^(\+?852\-?)?[569]\d{3}\-?\d{4}$/,
  22. 'en-IN': /^(\+?91|0)?[789]\d{9}$/,
  23. 'en-NZ': /^(\+?64|0)2\d{7,9}$/,
  24. 'en-ZA': /^(\+?27|0)\d{9}$/,
  25. 'en-ZM': /^(\+?26)?09[567]\d{7}$/,
  26. 'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
  27. 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/,
  28. 'fr-FR': /^(\+?33|0)[67]\d{8}$/,
  29. 'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
  30. 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
  31. 'ja-JP': /^(\+?81|0)\d{1,4}[ \-]?\d{1,4}[ \-]?\d{4}$/,
  32. 'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
  33. 'nb-NO': /^(\+?47)?[49]\d{7}$/,
  34. 'nl-BE': /^(\+?32|0)4?\d{8}$/,
  35. 'nn-NO': /^(\+?47)?[49]\d{7}$/,
  36. 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
  37. 'pt-BR': /^(\+?55|0)\-?[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/,
  38. 'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
  39. 'ru-RU': /^(\+?7|8)?9\d{9}$/,
  40. 'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
  41. 'tr-TR': /^(\+?90|0)?5\d{9}$/,
  42. 'vi-VN': /^(\+?84|0)?((1(2([0-9])|6([2-9])|88|99))|(9((?!5)[0-9])))([0-9]{7})$/,
  43. 'zh-CN': /^(\+?0?86\-?)?1[345789]\d{9}$/,
  44. 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/
  45. };
  46. /* eslint-enable max-len */
  47. // aliases
  48. phones['en-CA'] = phones['en-US'];
  49. phones['fr-BE'] = phones['nl-BE'];
  50. function isMobilePhone(str, locale) {
  51. (0, _assertString2.default)(str);
  52. if (locale in phones) {
  53. return phones[locale].test(str);
  54. }
  55. return false;
  56. }
  57. module.exports = exports['default'];