diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js
index f774b737..763df5b6 100644
--- a/__tests__/ExpensiMark-HTML-test.js
+++ b/__tests__/ExpensiMark-HTML-test.js
@@ -1844,9 +1844,15 @@ describe('when should keep raw input flag is enabled', () => {
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
- test('user mention from phone number', () => {
+ test('user mention from invalid phone number', () => {
const testString = '@+1234567890';
- const resultString = '@+1234567890';
+ const resultString = '@+1234567890';
+ expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
+ });
+
+ test('user mention from valid phone number', () => {
+ const testString = '@+15005550006';
+ const resultString = '@+15005550006';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
});
diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js
index afc4bcad..c1f437ff 100644
--- a/lib/ExpensiMark.js
+++ b/lib/ExpensiMark.js
@@ -214,7 +214,10 @@ export default class ExpensiMark {
return `${g1}${g2}${phoneRegex.test(g2) ? `@${Constants.CONST.SMS.DOMAIN}` : ''}`;
},
rawInputReplacement: (match, g1, g2) => {
- if (!Str.isValidMention(match)) {
+ const phoneNumberRegex = new RegExp(`^${Constants.CONST.REG_EXP.PHONE_PART}$`);
+ const mention = g2.slice(1);
+ const mentionWithoutSMSDomain = Str.removeSMSDomain(mention);
+ if (!Str.isValidMention(match) || (phoneNumberRegex.test(mentionWithoutSMSDomain) && !Str.isValidPhoneNumber(mentionWithoutSMSDomain))) {
return match;
}
return `${g1}${g2}`;