Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong regex for french postal code in isPostalCode #2478

Open
Maze-fr opened this issue Oct 21, 2024 · 2 comments · May be fixed by #2479
Open

Wrong regex for french postal code in isPostalCode #2478

Maze-fr opened this issue Oct 21, 2024 · 2 comments · May be fixed by #2479
Labels

Comments

@Maze-fr
Copy link

Maze-fr commented Oct 21, 2024

Describe the bug
When checking for french postal code with isPostalCode(..., 'FR'), I can use wrong values and get true.

Examples
No department number 96 in France, isPostalCode('96000', 'FR') is true but should be false.
The actual regex is : /^\d{2}\s?\d{3}$/.
Beside, we never use space in postal codes (never seen that in 45 years).

Correction
The basic rules is : department number (2-3 digits) + digits to have up to 5 digits length, and can start with 0 (see here).
The complete list of departments is available here.
Then, the a basic correct regex should be : /^(?:(?:0[1-9]|[1-8]\d|9[0-5])\d{3}|97[1-46]\d{2})$/.
It doesn't take into account some historical specific rules on the last 3 digits, but it's way better than the current one.

Additional context
Validator.js version: 13.12.0
Node.js version: 20.17.0
OS platform: Ubuntu 24.10

@WikiRik
Copy link
Member

WikiRik commented Oct 21, 2024

Feel free to open a PR with these changes

@Rajput-Balram
Copy link

@Maze-fr I came across this issue and have worked on a solution. I’d be happy to raise a PR if you’re okay with it. I’m new to open source and found this issue a great opportunity to contribute.

@Rajput-Balram Rajput-Balram linked a pull request Oct 21, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants