fix(isIdentityCard): accept province 8 (AJK) and female gender digit 0 for PK CNIC#2776
Open
chatman-media wants to merge 1 commit into
Open
fix(isIdentityCard): accept province 8 (AJK) and female gender digit 0 for PK CNIC#2776chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2776 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2587 2587
Branches 656 656
=========================================
Hits 2587 2587 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
isIdentityCard(str, 'PK')validates Pakistani CNIC numbers (formatXXXXX-XXXXXXX-X, 13 digits) with a regex that is stricter than the real CNIC specification in two ways:1-7, which rejects province code8= Azad Jammu & Kashmir (AJK). Valid CNICs use codes 1-8 (1 = Khyber Pakhtunkhwa, 2 = FATA, 3 = Punjab, 4 = Sindh, 5 = Balochistan, 6 = Islamabad, 7 = Gilgit-Baltistan, 8 = Azad Kashmir).1-9, which rejects0. The final digit encodes gender — odd digits for men, even digits for women — and0is a valid even/female digit.So a real AJK card such as
82345-2345678-7and a real female card ending in0such as45504-4185771-0are both incorrectly rejected today.Fix
[1-8]to include AJK (8).[0-9]to include the female0gender digit.The 5-7-1 digit structure and hyphen placement are unchanged, so previously-invalid inputs (province
0/9, wrong middle-part length, wrong overall length) remain invalid.Authoritative source
Wikipedia, CNIC (Pakistan) — https://en.wikipedia.org/wiki/CNIC_(Pakistan) :
Tests
Added to the
PKvalidfixtures intest/validators.test.js:82345-2345678-7,81234-1234567-3— province 8 (AJK)45504-4185771-0,34543-2323471-0— female gender digit 0All four are rejected by the old regex and accepted by the new one. The existing
invalidfixtures are unaffected.npm testpasses (318 passing, 100% statements/functions/lines) andnpm run lintis clean.