diff options
Diffstat (limited to 'converter.js')
-rw-r--r-- | converter.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/converter.js b/converter.js index 1c8ae81..f90fe59 100644 --- a/converter.js +++ b/converter.js @@ -32,6 +32,8 @@ function translateObjectToContact(inRec) { ValueError.prototype = new Error(); ValueError.prototype.constructor = ValueError; + const cleanPhoneNoRE = /[^0-9+]*/g; + /** * Find the proper record (or create new one) in the multi-value * attribute @@ -117,6 +119,14 @@ function translateObjectToContact(inRec) { } } + /** + * Firefox OS doesn’t recognize well formatted phone numbers, and + * works best with the plain number-only ones. + */ + function cleanPhoneNumber(inNo) { + return inNo.replace(cleanPhoneNoRE, ""); + } + for (var key in inRec) { if (["birthyear", "birthmonth", "birthday"].indexOf(key) !== -1) { // We have alternatively either whole date in birthyear field, @@ -159,14 +169,14 @@ function translateObjectToContact(inRec) { } else if (key === "facsimiletelephonenumber") { curRec = findSubElement("tel", "fax"); - curRec.value = inRec[key]; + curRec.value = cleanPhoneNumber(inRec[key]); } else if (key === "givenName") { contact.givenName = [inRec[key]]; } else if (key === "homePhone") { curRec = findSubElement("tel", "home"); - curRec.value = inRec[key]; + curRec.value = cleanPhoneNumber(inRec[key]); } else if (key === "l") { curRec = findSubElement("adr", "work"); @@ -182,7 +192,7 @@ function translateObjectToContact(inRec) { } else if (key === "mobile") { curRec = findSubElement("tel", "mobile"); - curRec.value = inRec[key]; + curRec.value = cleanPhoneNumber(inRec[key]); } else if (key === "mozillaHomeCountryName") { curRec = findSubElement("adr", "home"); @@ -275,7 +285,7 @@ function translateObjectToContact(inRec) { } else if (key === "telephoneNumber") { curRec = findSubElement("tel", "work"); - curRec.value = inRec[key]; + curRec.value = cleanPhoneNumber(inRec[key]); } else if (key === "title") { contact.jobTitle = [inRec[key]]; |