Skip to content

@IsPhoneNumber fails for valid Saudi Arabia (SA) numbers starting with +96657 #2664

Description

@Mohamed-Sa2024

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triageIssues which needs to be reproduced to be verified report.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions