Skip to content

Commit cfe05a1

Browse files
committed
Add some initial support for matching international phone numbers. Also, don't autolink numbers that have no phone number-like formatting.
1 parent 28d0b1a commit cfe05a1

File tree

4 files changed

+65
-82
lines changed

4 files changed

+65
-82
lines changed

dist/Autolinker.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,16 +1546,12 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
15461546
* See #6 for more info.
15471547
* 9. Group that is used to determine if there is a phone number match. The
15481548
* next 3 groups give segments of the phone number.
1549-
* 10. (Optional) Group that matches the area code of a phone number. Will
1550-
* be an empty string if not included in the number.
1551-
* 11. Group that matches the first 3 digits of a US phone number.
1552-
* 12. Group that matches the last 4 digits of a US phone number.
15531549
*/
15541550
matcherRegex : (function() {
15551551
var twitterRegex = /(^|[^\w])@(\w{1,15})/, // For matching a twitter handle. Ex: @gregory_jacobs
15561552

15571553
emailRegex = /(?:[\-;:&=\+\$,\w\.]+@)/, // something@ for email addresses (a.k.a. local-part)
1558-
phoneRegex = /\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})/, // ex: (123) 456-7890, 123 456 7890, 123-456-7890, etc.
1554+
phoneRegex = /(?:\+?\d{1,3}[-\s.])?\(?\d{3}\)?[-\s.]?\d{3}[-\s.]\d{4}/, // ex: (123) 456-7890, 123 456 7890, 123-456-7890, etc.
15591555
protocolRegex = /(?:[A-Za-z][-.+A-Za-z0-9]+:(?![A-Za-z][-.+A-Za-z0-9]+:\/\/)(?!\d+\/?)(?:\/\/)?)/, // match protocol, allow in format "http://" or "mailto:". However, do not match the first part of something like 'link:http://www.google.com' (i.e. don't match "link:"). Also, make sure we don't interpret 'google.com:8000' as if 'google.com' was a protocol here (i.e. ignore a trailing port number in this regex)
15601556
wwwRegex = /(?:www\.)/, // starting with 'www.'
15611557
domainNameRegex = /[A-Za-z0-9\.\-]*[A-Za-z0-9\-]/, // anything looking at all like a domain, non-unicode domains, not ending in a period
@@ -1616,7 +1612,6 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
16161612
'(',
16171613
phoneRegex.source,
16181614
')'
1619-
16201615
].join( "" ), 'gi' );
16211616
} )(),
16221617

0 commit comments

Comments
 (0)