Skip to content

Add postal code validation for Turkey (TR) - #2968

Open
Praiztl wants to merge 1 commit into
validatorjs:masterfrom
Praiztl:add-turkey-postal-code
Open

Praiztl wants to merge 1 commit into
validatorjs:masterfrom
Praiztl:add-turkey-postal-code

Conversation

@Praiztl

@Praiztl Praiztl commented Nov 20, 2026

Copy link
Copy Markdown

What

Adds postal code validation for Turkey (TR) to isPostalCode, requested in #2751.

Details

Turkish postal codes are five digits. The first two digits are the province code, which runs from 01 to 81; the last three identify the delivery area. The pattern enforces that province range:

TR: /^(0[1-9]|[1-7]\d|8[01])\d{3}$/

So 34000, 06810 and 81950 are accepted, while 00000, 82000 and any input that is not five digits are rejected.

Changes

  • src/lib/isPostalCode.js: add the TR pattern (between TN and TW).
  • test/validators.test.js: add a TR fixture with valid samples across several provinces and invalid samples (out-of-range province prefix, wrong length, letters).
  • README.md: add TR to the documented isPostalCode locale list.

No runtime dependencies added, and generated distributions were not committed.

Testing

The new fixture fails before the source change (Invalid locale 'TR') and passes after it. Full suite green: npm test gives 323 passing, lint clean.

Closes #2751.

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

Turkish postal codes are five digits where the first two identify the province (01-81). Adds the TR pattern to isPostalCode, a regression test with valid and invalid samples, and the TR entry in the README locale list. Closes validatorjs#2751.
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ff3424) to head (fdb7359).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2968   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2599      2599           
  Branches       658       658           
=========================================
  Hits          2599      2599           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Postal Code validation for Turkey

1 participant