Skip to content

Commit

Permalink
fix(validator): local country code issue
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Apr 26, 2023
1 parent 6e85476 commit 07e9cc0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/validator/src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ export function validator<T extends StringifyableRecord>(
export const sanitizePhoneNumber = (input?: string | number | null, countryCode = '98'): number | null => {
if (input == null) return null;

const unicodeDigits = new UnicodeDigits('en');
input = unicodeDigits.translate(input + '');

input =
countryCode +
(input + '').replace(/[ )(-]+/g, '').replace(new RegExp(`^(\\+${countryCode}|${countryCode}|\\+|0)`), '');
input.replace(/[ )(-]+/g, '').replace(new RegExp(`^(\\+${countryCode}|${countryCode}|\\+|0)`), '');

const unicodeDigits = new UnicodeDigits('en');
input = unicodeDigits.translate(input);
if (input.length !== countryCode.length + 10 || !isNumber(input)) return null;

if (input.length !== 12 || !isNumber(input)) return null;
return +input;
};

0 comments on commit 07e9cc0

Please sign in to comment.