Rexact
Cheatsheet

Regex Japanese postal code

The Japan Post manual writes the code as 7 digits with a hyphen between the 3rd and 4th ('100-0001'), ASCII digits only. On an address it is preceded by the 〒 symbol, which the manual does not mention. None of the three real attempts handles both: validator.js requires the hyphen and rejects '1000001', a Kuroco rule is not anchored so 'abc100-0001xyz' passes, and django-localflavor accepts both spellings but rejects '〒100-0001'. Here's an anchored pattern accepting an optional hyphen and an optional 〒, compared against those three real attempts.

/^(?:〒 ?)?[0-9]{3}-?[0-9]{4}$/
passes 26/26 cases

Comparison of existing patterns

Implementation

const re = new RegExp("^(?:〒 ?)?[0-9]{3}-?[0-9]{4}$", "");
re.test(input);

Limits

  • Valide seulement la FORME (7 chiffres, tiret facultatif après le 3e) : ne vérifie pas qu'un code est réellement attribué par la Poste japonaise. « 000-0000 » passe, alors qu'il n'est très probablement attribué à aucune adresse.
  • Le tiret facultatif et le préfixe « 〒 » sont des tolérances de saisie : le manuel de la Poste japonaise ne décrit que la forme avec tiret et ne mentionne pas « 〒 ». Si vous stockez le code, normalisez-le en « NNN-NNNN » sans 〒.
  • Rejette les chiffres pleine chasse (« 100-0001 ») : le manuel dit « 当分の間、算用数字のみ » (chiffres arabes seulement, pour l'instant). C'est un choix de la Poste, pas une loi : convertissez-les en ASCII avant validation si votre public saisit en japonais.
  • Un code à 7 chiffres ne dit rien de l'adresse : seul un fichier de correspondance code-adresse comme celui de la Poste japonaise confirme qu'un code existe et à quelle zone il correspond.

Postal codes for other countries

Related pages