From 1507ffcc3f2454fb27dd76cc453ebd6c3c489457 Mon Sep 17 00:00:00 2001 From: wanlingt Date: Wed, 18 Oct 2023 15:08:14 +0800 Subject: [PATCH] fix: format mobile no --- src/app/modules/sgid/sgid.adapter.ts | 4 +++- src/app/modules/sgid/sgid.format.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app/modules/sgid/sgid.adapter.ts b/src/app/modules/sgid/sgid.adapter.ts index ebe3d73710..2c3807afae 100644 --- a/src/app/modules/sgid/sgid.adapter.ts +++ b/src/app/modules/sgid/sgid.adapter.ts @@ -8,7 +8,7 @@ import { SGID_MYINFO_NRIC_NUMBER_SCOPE, SGIDScope as ExternalAttr, } from './sgid.constants' -import { formatAddress, formatVehicles } from './sgid.format' +import { formatAddress, formatMobileNo, formatVehicles } from './sgid.format' import { SGIDScopeToValue } from './sgid.types' const logger = createLoggerWithLabel(module) @@ -166,6 +166,8 @@ export class SGIDMyInfoData return formatAddress(fieldValue) case ExternalAttr.VehicleNo: return formatVehicles(fieldValue) + case ExternalAttr.MobileNoWithCountryCode: + return formatMobileNo(fieldValue) default: // SGID returns NA if they do not have the value. We want to return an empty string instead, // so that this can be processed by our frontend in the same way as Singpass MyInfo diff --git a/src/app/modules/sgid/sgid.format.ts b/src/app/modules/sgid/sgid.format.ts index 73d93dcc4d..450d4b8311 100644 --- a/src/app/modules/sgid/sgid.format.ts +++ b/src/app/modules/sgid/sgid.format.ts @@ -41,3 +41,14 @@ export const formatVehicles = (vehicles: string): string => { return '' } } + +/** + * Formats SGID MyInfo mobile number field by removing any white space + * @param mobileno + * @example '+65 88889999' + * @returns Whitespace is removed, for example '+6588889999' + */ +export const formatMobileNo = (mobileno: string): string => { + const formattedMobileNo = mobileno.replace(/(\s)+/g, '') + return formattedMobileNo +}