-
Notifications
You must be signed in to change notification settings - Fork 849
Description
Describe the bug The @IsPhoneNumber('SA') (or with no region specified) decorator fails to validate valid Saudi Arabian mobile numbers that use the 57 prefix (e.g., +96657XXXXXXX). These numbers are primarily assigned to Virgin Mobile or STC in Saudi Arabia and are fully operational.
To Reproduce Steps to reproduce the behavior:
Create a DTO with the @IsPhoneNumber() decorator.
Pass a phone number starting with +96657 (e.g., +966579386956).
Validation fails with: isPhoneNumber: phone must be a valid phone number.
Code Example
TypeScript
import { IsPhoneNumber } from 'class-validator';
export class CreateOtpDto {
@IsPhoneNumber('SA') // or @IsPhoneNumber()
phone: string;
}
// Data: { "phone": "+966579386956" }
Expected behavior The validator should return true for valid Saudi numbers starting with 57.
Actual behavior (Error Stack Trace)
JSON
{
"response": {
"message": [
{
"target": { "phone": "+966579386956" },
"value": "+966579386956",
"property": "phone",
"children": [],
"constraints": { "isPhoneNumber": "phone must be a valid phone number" }
}
],
"error": "Bad Request",
"statusCode": 400
}
}
Additional context This is likely due to an outdated version of google-libphonenumber or libphonenumber-js in the project dependencies, as the 057 range was added to the Saudi numbering plan more recently than other prefixes like 050, 055, etc.