Skip to content

Commit

Permalink
Merge pull request #697 from nkdengineer/fix/valid-phone-number
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich committed May 28, 2024
2 parents 484b980 + 9192abe commit a451327
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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 @@ -28,6 +28,7 @@
"url": "git+ssh://[email protected]/Expensify/JS-Libs.git"
},
"dependencies": {
"awesome-phonenumber": "^5.4.0",
"classnames": "2.5.0",
"clipboard": "2.0.11",
"eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0",
Expand Down

0 comments on commit a451327

Please sign in to comment.