🔢 半角数字 → 全角数字変換ツール
クロネコヤマトなどのフォーム対策に便利!
📄 このツールのHTMLコード(コピペOK)
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>半角数字 → 全角数字変換ツール</title>
<style>
textarea {
width: 100%;
max-width: 500px;
height: 100px;
font-size: 1rem;
}
</style>
</head>
<body>
<h2>半角数字→全角数字変換ツール</h2>
<textarea id="input" placeholder="例: 123-456"></textarea><br>
<button onclick="convertToZenkakuNumber()">全角に変換 ▶</button><br><br>
<textarea id="output" readonly></textarea><br>
<button onclick="copyOutput()">📋 コピー</button>
<script>
function convertToZenkakuNumber() {
const half = document.getElementById("input").value;
let full = "";
for (let i = 0; i < half.length; i++) {
const code = half.charCodeAt(i);
if (code >= 0x30 && code <= 0x39) {
full += String.fromCharCode(code + 0xFEE0);
} else if (code === 0x2D) {
full += "-";
} else {
full += half.charAt(i);
}
}
document.getElementById("output").value = full;
}
function copyOutput() {
const output = document.getElementById("output");
output.select();
document.execCommand("copy");
alert("✅ コピーしました!");
}
</script>
</body>
</html>
🧩 応用と活用方法
日本国内のフォーム入力では、電話番号や郵便番号などに「全角数字」が求められる場面があります。特に配送会社のラベル印字や一部の自治体申請フォームでは、半角のままだとエラーになる場合もあります。
このツールは、charCodeAt() を用いて文字コードを取得し、数値の範囲(0x30 ~ 0x39)に該当する場合に、全角の文字コード(+0xFEE0)へと変換します。さらに、-(ハイフン)も - に置き換える工夫がされています。
フォームの事前バリデーションやUX改善にも有効で、ユーザーが意識せずとも正しい形式で入力できるようになります。
今後は、アルファベットや記号の全角変換、さらにはカタカナの半角⇔全角変換などに発展させることで、より柔軟な入力サポートツールに進化させることができます。