Dev.to WebDev 🛠 Dev 👁 0 📖 2 min read

A WhatsApp link generator in one page, no backend

Phone numbers in Indonesia start with 0. wa.me links want the full international number: no zero, no plus sign, no spaces or dashes. So 0812-3456-7890 has to become 6281234567890 before the link works. I built a page th

Phone numbers in Indonesia start with 0. wa.me links want the full international number: no zero, no plus sign, no spaces or dashes. So 0812-3456-7890 has to become 6281234567890 before the link works.

I built a page that does this conversion: WhatsApp Link Generator. You type a number and a message, and you get a wa.me link that opens a chat with the text already typed. It runs entirely in the browser, so nothing you type leaves the page and there is no server or database to maintain.

The same rules run behind every WhatsApp button on Konsultasi Koding, my mentoring service for IT students. Here is the code, lightly reformatted for reading.

Normalize the number

function normalize(input) {
  const raw = input.trim();
  const digits = raw.replace(/\D/g, "");

  if (!digits) return "";
  if (raw.startsWith("+")) return digits;
  if (digits.startsWith("00")) return digits.slice(2);
  if (digits.startsWith("0")) return "62" + digits.slice(1);
  if (digits.startsWith("8")) return "62" + digits;
  return digits;
}

The order of the checks decides the result:

  • A leading + means you already gave a country code, so the function only strips symbols.
  • 00 is the international call prefix, so it gets dropped instead of becoming 62.
  • A leading 0 or 8 is treated as an Indonesian number and gets 62.
  • Anything else passes through as typed.

Validate loosely

const isValid = (n) => /^[1-9]\d{9,14}$/.test(n);

10 to 15 digits, first digit not 0. The page does not check whether the number exists. WhatsApp will tell you that. If the format is wrong, the error message shows what to type, like 62812…

Build the link

function buildLink(number, message) {
  const text = message.trim() ? `?text=${encodeURIComponent(message)}` : "";
  return `https://wa.me/${number}${text}`;
}

encodeURIComponent keeps line breaks and emoji intact. With the number left empty, the link becomes https://wa.me/?text=..., which opens the contact picker with your message ready. That works well for a share button.

I will keep building small tools like this one. Try this one at syahravi.id/tools/whatsapp-link-generator.

What small tool have you built that you still use every week?

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.