Last active
August 29, 2015 14:06
-
-
Save tosh1ki/6c4a1c8b64c11dd7450a to your computer and use it in GitHub Desktop.
Google Contacts上の電話番号を修正する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validatePhoneNumber() { | |
var contacts = ContactsApp.getAllContacts(), | |
cell = SpreadsheetApp.getActiveSpreadsheet().getRange('A1'), | |
row = 1, | |
pnumber = ''; | |
// spread sheet に表示する用 | |
cell.offset(0,0).setValue("FullName"); | |
cell.offset(0,1).setValue("PhoneNumber"); | |
// 連絡帳内のすべての人に以下を適用. | |
for(var i in contacts) { | |
var contact = contacts[i]; | |
// 各人が電話番号を持つ場合: | |
if(contact.getPhones().length != 0){ | |
// 複数の電話番号を持つ場合に対応: | |
for(var j in contact.getPhones()){ | |
pnumber = String(contact.getPhones()[j].getPhonepnumber()); | |
// 頭が`0`でない場合: | |
// (この辺の判定が雑) | |
if(pnumber.match(/^0\d{9,10}$/) == null){ | |
// 一応sheet上に表示しておく. | |
cell.offset(row, 0).setValue(contact.getFullName()); | |
cell.offset(row, 1).setValue('\''+pnumber); | |
row++; | |
// 元のデータを削除して,修正した番号を追加. | |
contact.getPhones()[j].deletePhoneField() | |
contact.addPhone(ContactsApp.Field.MOBILE_PHONE, '0'+pnumber) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment