| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
Autolinker.matcher.Phone = Autolinker.Util.extend( Autolinker.matcher.Matcher, { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
matcherRegex : /(?:(?:(?:(\+)?\d{1,3}[-\040.]?)?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]?\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)[-\040.]?(?:\d[-\040.]?){6,12}\d+))([,;]+[0-9]+#?)*/g, |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
parseMatches: function(text) { |
| 34 |
var matcherRegex = this.matcherRegex, |
| 35 |
tagBuilder = this.tagBuilder, |
| 36 |
matches = [], |
| 37 |
match; |
| 38 |
|
| 39 |
while ((match = matcherRegex.exec(text)) !== null) { |
| 40 |
|
| 41 |
var matchedText = match[0], |
| 42 |
cleanNumber = matchedText.replace(/[^0-9,;#]/g, ''), |
| 43 |
plusSign = !!(match[1] || match[2]), |
| 44 |
before = match.index == 0 ? '' : text.substr(match.index - 1, 1), |
| 45 |
after = text.substr(match.index + matchedText.length, 1), |
| 46 |
contextClear = !before.match(/\d/) && !after.match(/\d/); |
| 47 |
|
| 48 |
if (this.testMatch(match[3]) && this.testMatch(matchedText) && contextClear) { |
| 49 |
matches.push(new Autolinker.match.Phone({ |
| 50 |
tagBuilder: tagBuilder, |
| 51 |
matchedText: matchedText, |
| 52 |
offset: match.index, |
| 53 |
number: cleanNumber, |
| 54 |
plusSign: plusSign |
| 55 |
})); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
return matches; |
| 60 |
}, |
| 61 |
|
| 62 |
testMatch: function(text) { |
| 63 |
return /\D/.test(text); |
| 64 |
} |
| 65 |
|
| 66 |
} ); |