You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
@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.
Describe the bug
When checking for french postal code with
isPostalCode(..., 'FR')
, I can use wrong values and gettrue
.Examples
No department number
96
in France,isPostalCode('96000', 'FR')
istrue
but should befalse
.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
The text was updated successfully, but these errors were encountered: