Skip to content

Instantly share code, notes, and snippets.

@imroca
Last active June 17, 2026 16:04
Show Gist options
  • Select an option

  • Save imroca/2587a663708155bb07981699d7b8864e to your computer and use it in GitHub Desktop.

Select an option

Save imroca/2587a663708155bb07981699d7b8864e to your computer and use it in GitHub Desktop.
Paraguayan Zod MSISDN / Cellphone Schema Validator
import { z } from "zod";
const paraguayMobileRegex =
/^(?:(?:\+?595|0)9|9?)(?:8[1-7]|7[1-6]|9[1-5]|6[1-3])\d{6}$/;
export const paraguayPhoneSchema = z
.string()
.trim()
.regex(paraguayMobileRegex, "Número de celular paraguayo inválido")
.transform((val) => {
const core8 = val.replace(/\D/g, "").slice(-8); // operator + subscriber, e.g. "8112345"
const national = `9${core8}`; // "981123456"
return {
international: `595${national}`, // "595981123456"
local: `0${national}`, // "0981123456"
};
});
paraguayPhoneSchema.parse("+59598123456");
// { international: "59598123456", local: "0981123456" }
paraguayPhoneSchema.parse("81123456");
// { international: "59598123456", local: "0981123456" }
paraguayPhoneSchema.parse("0981123456");
// { international: "59598123456", local: "0981123456" }
function getOperator(e164: string): string {
const code = e164.slice(5, 7); // two digits after "+5959"
if (/^8[1-7]$/.test(code)) return "Tigo";
if (/^7[1-6]$/.test(code)) return "Personal";
if (/^9[1-5]$/.test(code)) return "Claro";
if (/^6[1-3]$/.test(code)) return "VOX";
return "Unknown";
}
getOperator(paraguayPhoneSchema.parse("81123456")); // "Tigo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment