-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PC-32700) feat(NC): add New Caledonian phone number check in SetPhon…
…eNumber (#7266) * (PC-32700) feat(NC): add New Caledonia phone number check * (PC-32700) feat(NC): use isPhoneNumberValid in SetPhoneNumberWithoutValidation * (PC-32700) feat(NC): fix Sonar issues for isPhoneNumberValid * Return server error message * Explicite onSuccess and onError * Use libphonenumber-js for number validation * Fix tests * Stop using "as" --------- Co-authored-by: Maxime Le Duc <[email protected]>
- Loading branch information
1 parent
94a7b12
commit d220ba3
Showing
12 changed files
with
107 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
19 changes: 0 additions & 19 deletions
19
src/features/identityCheck/pages/phoneValidation/helpers/isPhoneNumberValid.native.test.ts
This file was deleted.
Oops, something went wrong.
15 changes: 12 additions & 3 deletions
15
src/features/identityCheck/pages/phoneValidation/helpers/isPhoneNumberValid.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
export function isPhoneNumberValid(number: string) { | ||
// 9 digits, 10 if the first is a "0" that can be separated by whitespace, "." or "-". | ||
return Boolean(number.match(/^(?:0)?\s*[1-9](?:[\s.-]*\d{2}){4}$/)) | ||
import parsePhoneNumberFromString, { CountryCode, getCountries } from 'libphonenumber-js' | ||
|
||
function isCountryCode(code: string): code is CountryCode { | ||
const countries: string[] = getCountries() | ||
return countries.includes(code) | ||
} | ||
|
||
export function isPhoneNumberValid(number: string, country: string) { | ||
if (!isCountryCode(country)) return false | ||
|
||
const phoneNumber = parsePhoneNumberFromString(number, country) | ||
return phoneNumber?.isValid() ?? false | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.