-
-
Notifications
You must be signed in to change notification settings - Fork 931
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
Invalid zip/postal codes when using locale en_CA #1416
Comments
Oh interesting, I assume you don't mean the first letter but following letters? We don't have a strategy yet for post validating content generated by pattern 🤔 Could you provide some invalid generated postcodes? We can use these e.g. for negative tests. |
For sure. Here are some examples.
The following script can be used to generate more examples. const { faker } = require('@faker-js/faker');
faker.locale = 'en_CA';
for (let i = 0; i < 10; i++) {
const code = faker.address.zipCode();
if (code.match(/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/)) {
console.log(`${code} is valid`);
} else {
console.log(`${code} is invalid`);
}
} |
Our internal resources are currently filled with preparing the move to start with v8, So I'm sorry if we cannot handle a fix right now. Until then, would it be okay to just use a loop until a valid postcode was generated? |
No problem, I can work around it. Thanks for the quick response! |
@dbertouille Sorry, we kind of forgot about this issue. Are you willing to create a PR for this now? You might have to duplicate some lines e.g.
Maybe multiply it out fully and then pick 100 random patterns? |
I created a PR to fix this issue: Until the PR is merged, you can use the following workaround: const zipCode = faker.helpers.fake('{{helpers.fromRegExp("[ABCEGHJ-NPRSTVXY][0-9][ABCEGHJ-NPRSTV-Z] [0-9][ABCEGHJ-NPRSTV-Z][0-9]")}}'); |
Pre-Checks
Describe the bug
When generating zip codes (postal codes) using the en_CA locale, invalid codes are generated. The characters
D
,F
,I
,O
,Q
, orU
are not used in postal codes. This is can cause the randomly generated codes to fail validation.Reference Documentation
Minimal reproduction code
Additional Context
No response
Environment Info
System: OS: macOS 12.3 CPU: (8) arm64 Apple M1 Pro Memory: 96.56 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.17.0 - /opt/homebrew/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.15.0 - /opt/homebrew/bin/npm Browsers: Brave Browser: 106.1.44.101 Chrome: 105.0.5195.52 Safari: 15.4 npmPackages: @faker-js/faker: ^7.5.0 => 7.5.0
Which module system do you use?
Used Package Manager
npm
The text was updated successfully, but these errors were encountered: