Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ export default class ExpensiMark {
'gim',
),
replacement: (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;
}
const phoneRegex = new RegExp(`^@${Constants.CONST.REG_EXP.PHONE_PART}$`);
Expand Down
7 changes: 6 additions & 1 deletion lib/str.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,14 @@ declare const Str: {
/**
* Check for whether a phone number is valid.
* @param phone
* @deprecated use isValidE164Phone to validate E.164 phone numbers or isValidPhoneFormat to validate phone numbers in general
* @deprecated use isValidE164Phone to validate E.164 phone numbers, isValidPhoneFormat to validate phone number format, or isValidPhoneNumber to validate phone numbers in general
*/
isValidPhone(phone: string): boolean;
/**
* Check for whether a phone number is valid.
* @param phone
*/
isValidPhoneNumber(phone: string): boolean;
/**
* Check for whether a phone number is valid according to E.164 standard.
* @param phone
Expand Down
11 changes: 11 additions & 0 deletions lib/str.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-control-regex */
import _ from 'underscore';
import {parsePhoneNumber} from 'awesome-phonenumber';
import * as HtmlEntities from 'html-entities';
import * as Constants from './CONST';
import * as UrlPatterns from './Url';
Expand Down Expand Up @@ -930,6 +931,16 @@ const Str = {
return Constants.CONST.SMS.E164_REGEX.test(phone);
},

/**
* Check for whether a phone number is valid.
* @param {String} phone
*
* @return {bool}
*/
isValidPhoneNumber(phone) {
return parsePhoneNumber(phone).possible;
},

/**
* Check for whether a phone number is valid according to E.164 standard.
* @param {String} phone
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"url": "git+ssh://git@github.com/Expensify/JS-Libs.git"
},
"dependencies": {
"awesome-phonenumber": "^5.4.0",
"classnames": "2.5.0",
"clipboard": "2.0.11",
"html-entities": "^2.5.2",
Expand Down