Data and storage
Clean a CSV column
normalize
Rewrite a phone column in one notation and flag rows that need a person.
Try it
id,phone,status 1,03-5253-8111,ok 2,090-1234-5678,ok 3,03-1234-5678,check 4,092-513-5612,ok
How it works
Clean data in bulk without losing anything: rows that can be cleaned get the normalized number, and the rest keep their value with a check status.
Because japan-phone does not guess, a row like 03-1234-5678 is flagged instead of being saved as if it were real.
In each language
import { normalize } from "@kurashina-design/japan-phone";
// Rows of a CSV file with a phone column. Rows that cannot be cleaned keep their value and are flagged.
const rows = [["1", "03(5253)8111"], ["2", "090 1234 5678"], ["3", "03-1234-5678"], ["4", "TEL:092-513-5612"]];
console.log("id,phone,status");
for (const [id, phone] of rows) {
const number = normalize(phone);
console.log([id, number ? number.national : phone, number ? "ok" : "check"].join(","));
}
from japan_phone import normalize
# Rows of a CSV file with a phone column. Rows that cannot be cleaned keep their value and are flagged.
rows = [["1", "03(5253)8111"], ["2", "090 1234 5678"], ["3", "03-1234-5678"], ["4", "TEL:092-513-5612"]]
print("id,phone,status")
for row_id, phone in rows:
number = normalize(phone)
print(",".join([row_id, number.national if number else phone, "ok" if number else "check"]))
import jp.kurashina.japanphone.JapanPhoneNumber;
import jp.kurashina.japanphone.JapanPhone;
import java.util.Optional;
// Rows of a CSV file with a phone column. Rows that cannot be cleaned keep their value and are flagged.
String[][] rows = {{"1", "03(5253)8111"}, {"2", "090 1234 5678"}, {"3", "03-1234-5678"}, {"4", "TEL:092-513-5612"}};
System.out.println("id,phone,status");
for (String[] row : rows) {
Optional<JapanPhoneNumber> number = JapanPhone.normalize(row[1]);
String phone = number.map(JapanPhoneNumber::getNational).orElse(row[1]);
System.out.println(row[0] + "," + phone + "," + (number.isPresent() ? "ok" : "check"));
}
Output:
id,phone,status
1,03-5253-8111,ok
2,090-1234-5678,ok
3,03-1234-5678,check
4,092-513-5612,ok