Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Allow IsMobilePhone Decorator to Accept Multiple Locales #2489

Open
naithagoni opened this issue Jun 15, 2024 · 2 comments · May be fixed by #2492 or #2493
Open

feature: Allow IsMobilePhone Decorator to Accept Multiple Locales #2489

naithagoni opened this issue Jun 15, 2024 · 2 comments · May be fixed by #2492 or #2493
Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.

Comments

@naithagoni
Copy link

Description

I'm currently using the validation decorators in my NestJS DTOs. However, I'm encountering limitations with the IsMobilePhone decorator, as it only accepts a single locale. This issue persists with "class-validator": "^0.14.1".

For example:

@IsMobilePhone(
  'en-IN',
  { strictMode: true },
  {
    message: 'Phone number must be a valid Indian phone number',
  }
)
phoneNumber: string

Proposed Solution

The IsMobilePhone decorator should be enhanced to accept multiple locales. This would allow for validation against phone numbers from multiple regions. For instance:

@IsMobilePhone(
  ['en-IN', 'en-US', 'de-DE'],
  { strictMode: true },
  {
    message: 'Phone number must be a valid phone number',
  }
)
phoneNumber: string

This enhancement would significantly improve the flexibility and usability of the IsMobilePhone decorator.

@naithagoni naithagoni added flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features. labels Jun 15, 2024
@kurbar
Copy link

kurbar commented Jun 18, 2024

The underlying validator library (that class-validator uses under the hood for IsMobilePhone) actually supports specifying multiple locales as an array but the Decorator typing does not support it.

@townegr
Copy link

townegr commented Aug 5, 2024

From a previously related-issue, looks like there was some light chatter here: #1866 but not much follow-through. Any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.
3 participants