Fix phone number format
This commit is contained in:
parent
ee777a3363
commit
25a7d70c07
13
main.js
13
main.js
@ -34,12 +34,15 @@ var initialsynccomplete = false;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* From https://github.com/stevekinney/node-phone-formatter
|
* From https://github.com/stevekinney/node-phone-formatter
|
||||||
* @param {type} phoneNumber
|
* @param {string} phoneNumber
|
||||||
* @param {type} formatString
|
* @param {string} formatString
|
||||||
* @param {type} options
|
* @returns {string}
|
||||||
* @returns {unresolved}
|
|
||||||
*/
|
*/
|
||||||
function formatPhoneNumber(phoneNumber, formatString) {
|
function formatPhoneNumber(phoneNumber, formatString) {
|
||||||
|
phoneNumber = phoneNumber.replace(
|
||||||
|
/^[\+\d{1,3}\-\s]*\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/,
|
||||||
|
"$1$2$3"
|
||||||
|
);
|
||||||
for (var i = 0, l = phoneNumber.length; i < l; i++) {
|
for (var i = 0, l = phoneNumber.length; i < l; i++) {
|
||||||
formatString = formatString.replace("N", phoneNumber[i]);
|
formatString = formatString.replace("N", phoneNumber[i]);
|
||||||
}
|
}
|
||||||
@ -133,7 +136,7 @@ function createOrJoinSMSRoom(tel, ournumber, callback) {
|
|||||||
room_alias_name: "SMS_" + tel + "_" + ournumber,
|
room_alias_name: "SMS_" + tel + "_" + ournumber,
|
||||||
visibility: "private",
|
visibility: "private",
|
||||||
invite: settings.inviteusers,
|
invite: settings.inviteusers,
|
||||||
name: formatPhoneNumber(tel, "(NNN) NNN-NNNN"),
|
name: formatPhoneNumber(tel, "1 (NNN) NNN-NNNN"),
|
||||||
topic: "SMS conversation with " + tel + " (using " + ournumber + ")"
|
topic: "SMS conversation with " + tel + " (using " + ournumber + ")"
|
||||||
}).then((room) => {
|
}).then((room) => {
|
||||||
logger.debug("Room" + roomName + " created with ID " + room.room_id);
|
logger.debug("Room" + roomName + " created with ID " + room.room_id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user