智慧水务管理系统 - 精河县供水工程综合管理平台

phone-number-utils.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. // Regex that specifies any delimiter char that allows us to treat the number as
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. exports.isPhoneNumberSeparatorChar = isPhoneNumberSeparatorChar;
  5. exports.isPhoneNumberControlChar = isPhoneNumberControlChar;
  6. exports.isValidPhoneNumber = isValidPhoneNumber;
  7. // a phone number rather than just any other number that could appear in text.
  8. var hasDelimCharsRe = /[-. ()]/;
  9. // Over the years, many people have added to this regex, but it should have been
  10. // split up by country. Maybe one day we can break this down.
  11. var mostPhoneNumbers = /(?:(?:(?:(\+)?\d{1,3}[-. ]?)?\(?\d{3}\)?[-. ]?\d{3}[-. ]?\d{4})|(?:(\+)(?:9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)[-. ]?(?:\d[-. ]?){6,12}\d+))([,;]+[0-9]+#?)*/;
  12. // Regex for Japanese phone numbers
  13. var japanesePhoneRe = /(0([1-9]-?[1-9]\d{3}|[1-9]{2}-?\d{3}|[1-9]{2}\d{1}-?\d{2}|[1-9]{2}\d{2}-?\d{1})-?\d{4}|0[789]0-?\d{4}-?\d{4}|050-?\d{4}-?\d{4})/;
  14. // Combined regex
  15. var validPhoneNumberRe = new RegExp("^".concat(mostPhoneNumbers.source, "|").concat(japanesePhoneRe.source, "$"));
  16. /**
  17. * Determines if the character is a phone number separator character (i.e.
  18. * '-', '.', or ' ' (space))
  19. */
  20. function isPhoneNumberSeparatorChar(charCode) {
  21. return (charCode === 45 /* Char.Dash */ || // '-'
  22. charCode === 46 /* Char.Dot */ || // '.'
  23. charCode === 32 /* Char.Space */ // ' '
  24. );
  25. }
  26. /**
  27. * Determines if the character is a control character in a phone number. Control
  28. * characters are as follows:
  29. *
  30. * - ',': A 1 second pause. Useful for dialing extensions once the main phone number has been reached
  31. * - ';': A "wait" that waits for the user to take action (tap something, for instance on a smart phone)
  32. */
  33. function isPhoneNumberControlChar(charCode) {
  34. return (charCode === 44 /* Char.Comma */ || // ','
  35. charCode === 59 /* Char.SemiColon */ // ';'
  36. );
  37. }
  38. /**
  39. * Determines if the given phone number text found in a string is a valid phone
  40. * number.
  41. *
  42. * Our state machine parser is simplified to grab anything that looks like a
  43. * phone number, and this function confirms the match.
  44. */
  45. function isValidPhoneNumber(phoneNumberText) {
  46. // We'll only consider the match as a phone number if there is some kind of
  47. // delimiter character (a prefixed '+' sign, or separator chars).
  48. //
  49. // Accepts:
  50. // (123) 456-7890
  51. // +38755233976
  52. // Does not accept:
  53. // 1234567890 (no delimiter chars - may just be a random number that's not a phone number)
  54. var hasDelimiters = phoneNumberText.charAt(0) === '+' || hasDelimCharsRe.test(phoneNumberText);
  55. return hasDelimiters && validPhoneNumberRe.test(phoneNumberText);
  56. }
  57. //# sourceMappingURL=phone-number-utils.js.map