phone
This commit is contained in:
@@ -32,10 +32,11 @@ export class SmsService {
|
||||
name,
|
||||
value: value.toString(),
|
||||
}));
|
||||
const cleanedPhone = this.formatPhone(phone);
|
||||
|
||||
const smsData: ISmsBodyParameters = {
|
||||
Parameters: parametersArray,
|
||||
Mobile: phone,
|
||||
Mobile: cleanedPhone,
|
||||
TemplateId: templateId,
|
||||
};
|
||||
|
||||
@@ -57,4 +58,22 @@ export class SmsService {
|
||||
throw new HttpException('The SMS was not sent. Please try again later.', HttpStatus.BAD_GATEWAY);
|
||||
}
|
||||
}
|
||||
formatPhone(phone: string): string {
|
||||
// remove spaces, dashes, parentheses
|
||||
phone = phone.replace(/[^\d+]/g, '');
|
||||
|
||||
if (phone.startsWith('+98')) {
|
||||
return phone;
|
||||
}
|
||||
|
||||
if (phone.startsWith('98')) {
|
||||
return `+${phone}`;
|
||||
}
|
||||
|
||||
if (phone.startsWith('0')) {
|
||||
return `+98${phone.slice(1)}`;
|
||||
}
|
||||
|
||||
return `+98${phone}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user