Skip to content

Commit

Permalink
(PC-32700) feat(NC): fix Sonar issues for isPhoneNumberValid
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeneston-pass committed Nov 22, 2024
1 parent fa6c09b commit 5f5d09c
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@ export function isPhoneNumberValid(number: string, countryCallingCode: Country['
const startsWithZero = cleanedNumber.startsWith('0')
const startsWithOneToNine = /^[1-9]/.test(cleanedNumber)

const sixDigitRegex = /^\d{6}$/
const nineDigitRegex = /^[1-9]\d{8}$/
const tenDigitRegex = /^0\d{9}$/

switch (cleanedNumber.length) {
case 6:
return isCountryWithSixDigitsAfterCallingCode && Boolean(cleanedNumber.match(/^\d{6}$/))
return isCountryWithSixDigitsAfterCallingCode && !!sixDigitRegex.exec(cleanedNumber)
case 7:
case 8:
return false
case 9:
return (
isNotCountryWithSixDigitsAfterCallingCode &&
startsWithOneToNine &&
Boolean(cleanedNumber.match(/^[1-9]\d{8}$/))
!!nineDigitRegex.exec(cleanedNumber)
)
case 10:
return (
isNotCountryWithSixDigitsAfterCallingCode &&
startsWithZero &&
Boolean(cleanedNumber.match(/^0\d{9}$/))
!!tenDigitRegex.exec(cleanedNumber)
)
default:
return false
Expand Down

0 comments on commit 5f5d09c

Please sign in to comment.