@nexim/sanitizer
Version:
A collection of sanitization utilities for phone numbers and numeric inputs with TypeScript type safety.
31 lines (20 loc) • 1.09 kB
Markdown
[@nexim/sanitizer](../README.md) / sanitizePhoneNumber
# Function: sanitizePhoneNumber()
> **sanitizePhoneNumber**(`input`: `unknown`, `countryCode`: `string`): `null` \| `number`
Sanitizes a phone number by converting Unicode digits, removing special characters,
and standardizing the format with country code.
## Parameters
| Parameter | Type | Default value | Description |
| ------------- | --------- | ------------- | -------------------------------------------------- |
| `input` | `unknown` | `undefined` | The phone number input to sanitize |
| `countryCode` | `string` | `'98'` | The country code to apply (default: '98' for Iran) |
## Returns
`null` \| `number`
The sanitized phone number as a number, or null if invalid
## Example
```ts
sanitizePhoneNumber('09123456789'); // returns 989123456789
sanitizePhoneNumber('+98 912 345 6789'); // returns 989123456789
sanitizePhoneNumber('۰۹۱۲۳۴۵۶۷۸۹'); // returns 989123456789
sanitizePhoneNumber('invalid'); // returns null
```